package com.iplant.aps.serviceImpl;

import com.iplant.aps.service.APSService;
import com.iplant.aps.service.apsenum.aps.APSFirstCheckStatus;
import com.iplant.aps.service.apsenum.aps.APSShiftPeriod;
import com.iplant.aps.service.apsenum.aps.APSTaskStatus;
import com.iplant.aps.service.apsenum.oms.OMSOrderStatus;
import com.iplant.aps.service.po.aps.*;
import com.iplant.aps.service.po.aps.dayPlan.APSTaskPartPointDayParent;
import com.iplant.aps.service.po.aps.gantt.APSGanttData;
import com.iplant.aps.service.po.aps.gantt.APSGanttLink;
import com.iplant.aps.service.po.aps.impPo.APSMonthImpPo;
import com.iplant.aps.service.po.aps.impPo.APSMonthShowPo;
import com.iplant.aps.service.po.aps.impPo.APSWeekthImpPo;
import com.iplant.aps.service.po.aps.table.APSTableRow;
import com.iplant.aps.service.po.aps.table.APSTableRowDetail;
import com.iplant.aps.service.po.aps.table.APSTableTitle;
import com.iplant.aps.service.po.oms.OMSOrder;
import com.iplant.aps.service.po.oms.OMSOutsourceOrder;
import com.iplant.aps.service.po.sch.APSMessage;
import com.iplant.aps.serviceImpl.dao.APSTaskPartDAO;
import com.iplant.aps.serviceImpl.dao.APSTaskPartPointDAO;
import com.iplant.aps.serviceImpl.dao.aps.APSTaskPartPointDayDAO;
import com.iplant.aps.serviceImpl.dao.oms.OMSOrderDAO;
import com.iplant.aps.serviceImpl.utils.aps.APSAutoUtils;
import com.iplant.base.po.OutResult;
import com.iplant.base.po.Pagination;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.po.enums.ExceptionTypes;
import com.iplant.base.po.excel.ExcelData;
import com.iplant.base.po.excel.ExcelLineData;
import com.iplant.base.po.excel.ExcelSheetData;
import com.iplant.base.utils.cache.CacheUtils;
import com.iplant.base.utils.general.CalendarTool;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.base.utils.sql.orm.ORMUtils;
import com.iplant.base.utils.sql.orm.PoService;
import com.iplant.base.utils.tasker.TaskTimerUtils;
import com.iplant.basic.service.basicenum.bfc.FMCShiftType;
import com.iplant.basic.service.po.bms.BMSClassInfo;
import com.iplant.basic.service.po.bms.BMSClassRange;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.basic.service.po.cfg.CFGCalendar;
import com.iplant.basic.service.po.crm.CRMCustomer;
import com.iplant.basic.service.po.fmc.FMCFactory;
import com.iplant.basic.serviceImpl.BMSServiceImpl;
import com.iplant.basic.serviceImpl.dao.bfc.BFCSystemConfigDAO;
import com.iplant.basic.utils.ExcelUtil;
import com.iplant.pdm.service.basicenum.fpc.FPCRouteType;
import com.iplant.pdm.service.po.bop.FPCRoute;
import com.iplant.pdm.service.po.bop.FPCRoutePart;
import com.iplant.pdm.service.po.bop.FPCRoutePartPoint;
import com.iplant.pdm.service.po.fmc.FMCLine;
import com.iplant.pdm.service.po.fpc.FPCProduct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class APSServiceImpl implements APSService {
    private static Logger logger = LoggerFactory.getLogger(BMSServiceImpl.class);

    private static APSService _Instance;

    public static APSService getInstance() {
        if (_Instance == null)
            _Instance = new APSServiceImpl();

        return _Instance;
    }

    public APSServiceImpl() {
    }

    //region POService
    private PoService<OMSOrder> mOMSOrderService = ORMUtils.GetPoService(OMSOrder.class);
    private PoService<FMCFactory> mFMCFactoryService = ORMUtils.GetPoService(FMCFactory.class);
    private PoService<FPCProduct> mFPCProductService = ORMUtils.GetPoService(FPCProduct.class);
    private PoService<FMCLine> mFMCLineService = ORMUtils.GetPoService(FMCLine.class);
    private PoService<CRMCustomer> mCRMCustomerService = ORMUtils.GetPoService(CRMCustomer.class);
    private PoService<FPCRoute> mFPCRouteService = ORMUtils.GetPoService(FPCRoute.class);
    private PoService<FPCRoutePart> mFPCRoutePartService = ORMUtils.GetPoService(FPCRoutePart.class);
    private PoService<FPCRoutePartPoint> mFPCRoutePartPointService = ORMUtils.GetPoService(FPCRoutePartPoint.class);
    private PoService<APSSchedulingVersionBPM> mAPSSchedulingVersionBPMService =
            ORMUtils.GetPoService(APSSchedulingVersionBPM.class);
    private PoService<APSTaskPart> mAPSTaskPartService =
            ORMUtils.GetPoService(APSTaskPart.class);
    private PoService<APSTaskPartPoint> mAPSTaskPartPointService =
            ORMUtils.GetPoService(APSTaskPartPoint.class);
    private PoService<APSTaskPartPointDay> mAPSTaskPartPointDayService =
            ORMUtils.GetPoService(APSTaskPartPointDay.class);
    private PoService<BMSClassInfo> mBMSClassInfoService =
            ORMUtils.GetPoService(BMSClassInfo.class);
    private PoService<BMSClassRange> mBMSClassRangeService =
            ORMUtils.GetPoService(BMSClassRange.class);

    //endregion

    //region 计划排程
    public ServiceResult<List<APSTaskPart>> APS_ScheduleTaskPart(BMSEmployee wLoginUser, List<OMSOrder> wOMSOrderList
            , Calendar wStartDate, Calendar wEndDate) {
        return null;
    }

    @Override
    public ServiceResult<List<Map<String, Object>>> APS_QueryTableInfoList(BMSEmployee wLoginUser, Calendar wStartTime,
                                                                           Calendar wEndTime, int wAPSShiftPeriod) {
        ServiceResult<List<Map<String, Object>>> wResult = new ServiceResult<>();
        try {

        } catch (Exception e) {
            logger.error(
                    StringUtils.Format("{0} {1} ex：{2}", "APSServiceImpl", "APS_QueryTableInfoList", e.toString()));
        }
        return wResult;
    }

    public ServiceResult<List<APSTaskPart>> APS_AutoTaskPart(BMSEmployee wLoginUser, List<OMSOrder> wOrderList,
                                                             APSShiftPeriod wShiftPeriod, int wAllowTechDelayHour,
                                                             boolean wCheckMaterialBool, Calendar wStartTime,
                                                             Calendar wEndTime) {
        ServiceResult<List<APSTaskPart>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            List<APSMessage> wAPSMessageList = new ArrayList<>();

            //获取某一个订单对应的工艺类型
            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("ID", wOrderList.get(0).RouteID);
            FPCRoute wFPCRoute = mFPCRouteService.SelectPO(wLoginUser, wParams, wErrorCode);
            if (wFPCRoute == null || wFPCRoute.ID == 0) {
                wResult.FaultCode += "订单工艺路线数据缺失!";
                return wResult;
            }

            wResult.Result = APSAutoUtils.getInstance().APS_AutoTaskPart(wLoginUser,
                    FPCRouteType.getEnumType(wFPCRoute.TypeID), wOrderList, wShiftPeriod, wStartTime, wEndTime,
                    wCheckMaterialBool, wAllowTechDelayHour, wAPSMessageList);

            for (APSTaskPart wAPSTaskPart : wResult.Result) {
                for (APSTaskPartPoint wAPSTaskPartPoint : wAPSTaskPart.TaskPartPointList) {
                    wAPSTaskPartPoint.OrderNo = wAPSTaskPart.OrderNo;
                    wAPSTaskPartPoint.RoutePartName = wAPSTaskPart.RoutePartName;
                }
            }

            wResult.CustomResult.put("MessageList", wAPSMessageList);

            // 排序
            wResult.Result.sort(Comparator.comparing(APSTaskPart::getRoutePartOrder));

            //表头数据
            List<APSTableTitle> wAPSTableTitleList = new ArrayList<>();
            APSTableTitle wAPSTableTitle;
            for (APSTaskPart wAPSTaskPart : wResult.Result) {
                if (wAPSTableTitleList.stream().anyMatch(p -> p.RoutePartName.equals(wAPSTaskPart.RoutePartName))) {
                    continue;
                }

                wAPSTableTitle = new APSTableTitle();
                wAPSTableTitle.RoutePartName = wAPSTaskPart.RoutePartName;
                wAPSTableTitleList.add(wAPSTableTitle);
            }
            wResult.CustomResult.put("APSTableTitleList", wAPSTableTitleList);

            //表格行数据
            List<APSTableRow> wAPSTableRowList = new ArrayList<>();
            List<APSTaskPart> wAPSTaskPartList;
            APSTableRow wAPSTableRow;
            APSTableRowDetail wAPSTableRowDetail;
            for (OMSOrder wOMSOrder : wOrderList) {
                wAPSTaskPartList =
                        wResult.Result.stream().filter(p -> p.OrderID == wOMSOrder.ID).collect(Collectors.toList());
                wAPSTableRow = new APSTableRow();
                wAPSTableRow.OMSOrder = wOMSOrder;
                wAPSTableRow.Details = new ArrayList<>();
                for (APSTaskPart wAPSTaskPart : wAPSTaskPartList) {
                    wAPSTableRowDetail = new APSTableRowDetail();
                    wAPSTableRowDetail.RoutePartID = wAPSTaskPart.RoutePartID;
                    wAPSTableRowDetail.RoutePartName = wAPSTaskPart.RoutePartName;
                    wAPSTableRowDetail.StartTime = wAPSTaskPart.PartStartTime;
                    wAPSTableRowDetail.EndTime = wAPSTaskPart.PartEndTime;
                    wAPSTableRowDetail.PlanDayNum = wAPSTaskPart.PlanDayNum;
                    wAPSTableRow.Details.add(wAPSTableRowDetail);
                }
                wAPSTableRowList.add(wAPSTableRow);
            }
            wResult.CustomResult.put("APSTableRowList", wAPSTableRowList);

            //获取甘特图数据
            List<APSGanttLink> wAPSGanttLinkList = new ArrayList<>();
            List<FPCRoutePart> wFPCRoutePartList = new ArrayList<>();
            List<FPCRoutePartPoint> wFPCRoutePartPointList = new ArrayList<>();
            if (wResult.Result.size() > 0) {
                Map<String, Object> wParams1 = new HashMap<String, Object>();
                wFPCRoutePartList = mFPCRoutePartService.SelectPOList(wLoginUser,
                        wResult.Result.stream().map(p -> p.RoutePartID).distinct().collect(Collectors.toList()),
                        wParams1, Pagination.getMaxSize(), wErrorCode);
                List<Integer> wRoutePartPointIDList = new ArrayList<>();
                for (APSTaskPart wAPSTaskPart : wResult.Result) {
                    for (APSTaskPartPoint wAPSTaskPartPoint : wAPSTaskPart.TaskPartPointList) {
                        if (wRoutePartPointIDList.stream().noneMatch(p -> p == wAPSTaskPartPoint.RoutePartPointID)) {
                            wRoutePartPointIDList.add(wAPSTaskPartPoint.RoutePartPointID);
                        }
                    }
                }
                if (wRoutePartPointIDList.size() > 0) {
                    wFPCRoutePartPointList = mFPCRoutePartPointService.SelectPOList(wLoginUser,
                            wRoutePartPointIDList,
                            wParams1, Pagination.getMaxSize(), wErrorCode);
                }
            }

            //获取甘特图数据+连线数据
            List<APSGanttData> wAPSGanttDataList = APSTaskPartDAO.getInstance().APS_GetAPSGanttDataList(wLoginUser,
                    wResult.Result, wOrderList, wAPSGanttLinkList, wFPCRoutePartList, wFPCRoutePartPointList,
                    wErrorCode);
            wResult.CustomResult.put("APSGanttData", wAPSGanttDataList);
            wResult.CustomResult.put("APSGanttLink", wAPSGanttLinkList);

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            logger.error("APS_AutoTaskPart", e);
        }
        return wResult;
    }

    public ServiceResult<List<APSMessage>> APS_CheckTaskPart(BMSEmployee wLoginUser, List<OMSOrder> wOrderList,
                                                             List<APSTaskPart> wCheckTaskList,
                                                             APSShiftPeriod wShiftPeriod,
                                                             List<APSTaskPart> wOrderPartIssuedList,
                                                             List<OMSOutsourceOrder> wOutsourceOrderList,
                                                             Calendar wStartTime, Calendar wEndTime,
                                                             Map<Integer, List<FPCRoutePart>> wRoutePartList,
                                                             List<APSManuCapacity> wManuCapacityList, int wWorkDay) {
        ServiceResult<List<APSMessage>> wResult = new ServiceResult<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            Map<Integer, List<CFGCalendar>> wCalendarMap;

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            logger.error(StringUtils.Format("{0} {1} ex：{2}",
                    "APSServiceImpl", "APS_CheckTaskPart", e.toString()));
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> APS_SaveTaskPartList(BMSEmployee wLoginUser, Calendar wStartTime, Calendar wEndTime
            , List<APSTaskPart> wTaskPartList, List<APSMessage> wMessageList) {
        return null;
    }

    //endregion

    //region 订单管理

    @Override
    public ServiceResult<Integer> OMS_ImportOrder(BMSEmployee wLoginUser, ExcelData wExcelData) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelData == null || wExcelData.sheetData == null || wExcelData.sheetData.size() == 0) {
                wResult.FaultCode += "导入失败：Excel格式错误!";
                return wResult;
            }

            Map<String, Object> wParams = new HashMap<String, Object>();

            //工厂数据
//            List<FMCFactory> wFMCFactoryList = mFMCFactoryService.SelectPOList(wLoginUser, wParams,
//                    Pagination.getMaxSize(), wErrorCode);
            //产品数据
            List<FPCProduct> wFPCProductList = mFPCProductService.SelectPOList(wLoginUser, wParams,
                    Pagination.getMaxSize(), wErrorCode);
            //产线数据
            List<FMCLine> wFMCLineList = mFMCLineService.SelectPOList(wLoginUser, wParams,
                    Pagination.getMaxSize(), wErrorCode);
            //客户数据
            List<CRMCustomer> wCRMCustomerList = mCRMCustomerService.SelectPOList(wLoginUser, wParams,
                    Pagination.getMaxSize(), wErrorCode);

            Calendar wBaseTime = Calendar.getInstance();
            wBaseTime.set(2010, 0, 1, 0, 0, 0);

            ExcelSheetData wExcelSheetData = wExcelData.sheetData.get(0);
            int wIndex = 0;
            int wFactoryID = 0;
            String wCode = "";
            int wProductID = 0;
            int wLineID = 0;
            int wCustomerID = 0;
            double wFQTY = 0;
            Calendar wPlanStartDate = Calendar.getInstance();
            Calendar wRealStartDate = Calendar.getInstance();
            Calendar wPlanFinishDate = Calendar.getInstance();
            Calendar wRealFinishDate = Calendar.getInstance();
            Calendar wPutDate = Calendar.getInstance();
            String wDescription = "";
            int wStatus = 0;
            OMSOrder wOrder = null;
            ExcelLineData wExcelLineData;
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                //标题行数据，不处理
                if (i == 0) {
                    continue;
                }

                //获取Excel行数据
                wExcelLineData = wExcelSheetData.lineData.get(i);

                if (wExcelSheetData.lineData.get(i).colData.size() < 12) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，数据应为12列，实际{1}列!", String.valueOf(i + 1),
                            wExcelSheetData.lineData.get(i).colData.size());
                    return wResult;
                }

                //①获取工厂
//                String wFactoryCol = wExcelLineData.colData.get(wIndex++);
//                if (StringUtils.isEmpty(wFactoryCol)) {
//                    wResult.FaultCode += StringUtils.Format("提示：第【{0}】行数据有误，工厂不能为空!", String.valueOf(i + 1));
//                    return wResult;
//                }
//                if (wFMCFactoryList.stream().noneMatch(p -> p.Name.equals(wFactoryCol))) {
//                    wResult.FaultCode += StringUtils.Format("提示：第【{0}】行数据有误，【{1}】工厂不存在!", String.valueOf(i + 1),
//                            wFactoryCol);
//                    return wResult;
//                }
//                wFactoryID = wFMCFactoryList.stream().filter(p -> p.Name.equals(wFactoryCol)).findFirst().get().ID;
                //②获取产品
                String wProductCol = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wProductCol)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，产品不能为空!", String.valueOf(i + 1));
                    return wResult;
                }
                if (wFPCProductList.stream().noneMatch(p -> p.Code.equals(wProductCol))) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，【{1}】产品不存在!", String.valueOf(i + 1),
                            wProductCol);
                    return wResult;
                }
                wProductID = wFPCProductList.stream().filter(p -> p.Code.equals(wProductCol)).findFirst().get().ID;
                //②获取订单编码
                wCode = wExcelLineData.colData.get(wIndex++);
                //⑧获取数量
                String wNumberCol = wExcelLineData.colData.get(wIndex++);
                wFQTY = StringUtils.parseDouble(wNumberCol);
                if (wFQTY <= 0) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，数量不能小于或等于0!", String.valueOf(i + 1));
                    return wResult;
                }
                //③获取产线
                String wLineCol = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wLineCol)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，产线不能为空!", String.valueOf(i + 1));
                    return wResult;
                }
                if (wFMCLineList.stream().noneMatch(p -> p.Name.equals(wLineCol))) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，【{1}】产线不存在!", String.valueOf(i + 1),
                            wLineCol);
                    return wResult;
                }
                wLineID = wFMCLineList.stream().filter(p -> p.Name.equals(wLineCol)).findFirst().get().ID;
                wFactoryID = wFMCLineList.stream().filter(p -> p.Name.equals(wLineCol)).findFirst().get().FactoryID;
                //④获取客户
                String wCustomerCol = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCustomerCol)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，客户不能为空!", String.valueOf(i + 1));
                    return wResult;
                }
                if (wCRMCustomerList.stream().noneMatch(p -> p.Name.equals(wCustomerCol))) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，【{1}】客户不存在!", String.valueOf(i + 1),
                            wCustomerCol);
                    return wResult;
                }
                wCustomerID = wCRMCustomerList.stream().filter(p -> p.Name.equals(wCustomerCol)).findFirst().get().ID;
                //⑤获取WBS号
//                String wWBSCol = wExcelLineData.colData.get(wIndex++);
//                if (StringUtils.isEmpty(wWBSCol)) {
//                    wResult.FaultCode += StringUtils.Format("提示：第【{0}】行数据有误，WBS号不能为空!", String.valueOf(i + 1));
//                    return wResult;
//                }
                //⑥获取订单号
//                String wOrderNoCol = wExcelLineData.colData.get(wIndex++);
//                if (StringUtils.isEmpty(wOrderNoCol)) {
//                    wResult.FaultCode += StringUtils.Format("提示：第【{0}】行数据有误，订单号不能为空!", String.valueOf(i + 1));
//                    return wResult;
//                }
                //⑦获取工件号
//                String wWorkPieceNoCol = wExcelLineData.colData.get(wIndex++);
//                if (StringUtils.isEmpty(wWorkPieceNoCol)) {
//                    wResult.FaultCode += StringUtils.Format("提示：第【{0}】行数据有误，工件号不能为空!", String.valueOf(i + 1));
//                    return wResult;
//                }

                //⑨获取计划开工日期
                String wPlanStartDateCol = wExcelLineData.colData.get(wIndex++);
                wPlanStartDate = StringUtils.parseCalendar(wPlanStartDateCol);
                if (wPlanStartDate.compareTo(wBaseTime) <= 0) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，计划开工日期数据不合法!", String.valueOf(i + 1));
                    return wResult;
                }
                //⑨获取实际开工日期
                String wRalStartDateCol = wExcelLineData.colData.get(wIndex++);
                wRealStartDate = StringUtils.parseCalendar(wRalStartDateCol);
//                if (wRealStartDate.compareTo(wBaseTime) <= 0) {
//                    wResult.FaultCode += StringUtils.Format("提示：第【{0}】行数据有误，计划开工日期数据不合法!", String.valueOf(i + 1));
//                    return wResult;
//                }
                //①获取预计完工日期
                String wPlanFinishDateCol = wExcelLineData.colData.get(wIndex++);
                wPlanFinishDate = StringUtils.parseCalendar(wPlanFinishDateCol);
                if (wPlanFinishDate.compareTo(wBaseTime) <= 0) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，预计完工日期数据不合法!", String.valueOf(i + 1));
                    return wResult;
                }
                if (wPlanFinishDate.compareTo(wPlanStartDate) < 0) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，预计完工日期不能小于预计开工日期!",
                            String.valueOf(i + 1));
                    return wResult;
                }
                //⑨获取实际完工日期
                String wRealFinishDateCol = wExcelLineData.colData.get(wIndex++);
                wRealFinishDate = StringUtils.parseCalendar(wRealFinishDateCol);
//                if (wRealFinishDate.compareTo(wBaseTime) <= 0) {
//                    wResult.FaultCode += StringUtils.Format("提示：第【{0}】行数据有误，计划开工日期数据不合法!", String.valueOf(i + 1));
//                    return wResult;
//                }
                //⑨获取交货日期
                String wSendDateCol = wExcelLineData.colData.get(wIndex++);
                wPutDate = StringUtils.parseCalendar(wSendDateCol);
                //③获取描述
                wDescription = wExcelLineData.colData.get(wIndex++);
                //④初始化订单状态
                wStatus = OMSOrderStatus.getEnumType(wExcelLineData.colData.get(wIndex++)).getValue();
                if (wStatus <= 0) {
                    wStatus = OMSOrderStatus.HasOrder.getValue();
                }

                wOrder = new OMSOrder();
                wOrder.Code = wCode;
                wOrder.FactoryID = wFactoryID;
                wOrder.ProductID = wProductID;
                wOrder.LineID = wLineID;
                wOrder.CustomerID = wCustomerID;
//                wOrder.WBSNo = wWBSCol;
//                wOrder.Code = wOrderNoCol;
//                wOrder.PartNo = wWorkPieceNoCol;
                wOrder.FQTYPlan = (int) wFQTY;
                wOrder.PlanReceiveDate = wPlanStartDate;
                wOrder.RealReceiveDate = wRealStartDate;
                wOrder.PlanFinishDate = wPlanFinishDate;
                wOrder.RealFinishDate = wRealFinishDate;
                wOrder.DriverOnTime = wPutDate;
                wOrder.Description = wDescription;
                wOrder.Status = wStatus;
                wOrder.CreatorID = wLoginUser.ID;
                wOrder.CreateTime = Calendar.getInstance();
                wOrder.EditorID = wLoginUser.ID;
                wOrder.EditTime = Calendar.getInstance();

                int wNewID = APSServiceImpl.getInstance().OMS_UpdateOrder(wLoginUser, wOrder).Result;
                if (wNewID <= 0) {
                    wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.Result).getLabel();
                    return wResult;
                }
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> OMS_CompleteProcess(BMSEmployee wLoginUser, OMSOrder wOMSOrder) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wOMSOrder.RouteID <= 0) {
                wResult.FaultCode += "该订单未设置工艺路线!";
                return wResult;
            }
            wOMSOrder.Status = OMSOrderStatus.ProductReady.getValue();
            wOMSOrder.setUserInfo(wLoginUser);
            wOMSOrder.TelegraphTime = Calendar.getInstance();
            wOMSOrder.EditorID = wLoginUser.ID;
            wOMSOrder.EditTime = Calendar.getInstance();
            wOMSOrder.RealReceiveDate = Calendar.getInstance();
            mOMSOrderService.UpdatePo(wLoginUser, wOMSOrder, wErrorCode);

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> OMS_StatusSet(BMSEmployee wLoginUser, OMSOrder wOMSOrder, int wStatus) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            switch (OMSOrderStatus.getEnumType(wStatus)) {
                case Producing:
                    if (wOMSOrder.Status != OMSOrderStatus.Suspend.getValue()) {
                        wResult.FaultCode += "开工失败：只允许开工状态为`暂停`的订单";
                        return wResult;
                    }
                    break;
                case Suspend:
                    if (wOMSOrder.Status != OMSOrderStatus.Producing.getValue()) {
                        wResult.FaultCode += "暂停失败：只允许暂停状态为`生产中`的订单";
                        return wResult;
                    }

                    if (StringUtils.isEmpty(wOMSOrder.Description)) {
                        wResult.FaultCode += "暂停失败：未填写暂停的备注";
                        return wResult;
                    }
                    break;
                case FinishedWork:
                    if (wOMSOrder.Status != OMSOrderStatus.Producing.getValue()
                            && wOMSOrder.Status != OMSOrderStatus.Suspend.getValue()) {
                        wResult.FaultCode += "完工失败：只允许完工状态为`生产中`或`暂停`的订单";
                        return wResult;
                    }

                    wOMSOrder.RealFinishDate = Calendar.getInstance();
                    break;
                default:
                    break;
            }

            wOMSOrder.Status = wStatus;
            wOMSOrder.setUserInfo(wLoginUser);
            wOMSOrder.EditorID = wLoginUser.ID;
            mOMSOrderService.UpdatePo(wLoginUser, wOMSOrder, wErrorCode);

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> OMS_UpdateOrder(BMSEmployee wLoginUser, OMSOrder wOMSOrder) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wOMSOrder.ID <= 0) {
                //查询工艺路线
                Map<String, Object> wParams = new HashMap<String, Object>();
                wParams.put("ProductID", wOMSOrder.ProductID);
                wParams.put("LineID", wOMSOrder.LineID);
                wParams.put("CustomerID", wOMSOrder.CustomerID);
                wParams.put("Active", 1);
                wParams.put("IsStandard", 1);
                FPCRoute wFPCRoute = mFPCRouteService.SelectPO(wLoginUser, wParams,
                        wErrorCode);
                if (wFPCRoute != null && wFPCRoute.ID > 0) {
                    wOMSOrder.RouteID = wFPCRoute.ID;
                }
            }
            wOMSOrder.setUserInfo(wLoginUser);
            mOMSOrderService.UpdatePo(wLoginUser, wOMSOrder, wErrorCode);
            wResult.Result = wOMSOrder.ID;

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    //endregion

    //region 日计划

    @Override
    public ServiceResult<List<APSTaskPartPointDay>> APS_QueryDayPlan(BMSEmployee wLoginUser,
                                                                     Map<String, Object> wParams, Calendar wDate,
                                                                     Pagination wPagination) {
        ServiceResult<List<APSTaskPartPointDay>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            wParams.put("TaskPartStatus", APSTaskStatus.Issued.getValue());
            wParams.put("Status", APSTaskStatus.Saved.getValue());
            wParams.put("StationDate", wDate);
            wResult.Result = mAPSTaskPartPointDayService.SelectPOList(wLoginUser, wParams, wPagination, wErrorCode);

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<APSTaskPartPointDayParent>> APS_QueryDayPlanParent(BMSEmployee wLoginUser, Map<String,
            Object> wParams, Calendar wDate, Pagination wPagination) {
        ServiceResult<List<APSTaskPartPointDayParent>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            int wOrderID = StringUtils.parseInt(wParams.get("OrderID"));
            String wRoutePartName = StringUtils.parseString(wParams.get("RoutePartName"));
            String wRoutePartPointName = StringUtils.parseString(wParams.get("RoutePartPointName"));

            wDate.set(Calendar.HOUR_OF_DAY, 23);
            wDate.set(Calendar.MINUTE, 59);
            wDate.set(Calendar.SECOND, 59);

            wResult.Result = APSTaskPartPointDayDAO.getInstance().APS_QueryDayPlanParent(wDate,
                    wOrderID, wRoutePartName, wRoutePartPointName, wPagination, wErrorCode);

            //排序（订单倒序→工艺升序→工序升序）
            wResult.Result.sort(Comparator.comparing(APSTaskPartPointDayParent::getOrderID, Comparator.reverseOrder())
                    .thenComparing(APSTaskPartPointDayParent::getRoutePartOrder)
                    .thenComparing(APSTaskPartPointDayParent::getRoutePartPointOrder));

            Calendar wSTime = Calendar.getInstance();
            wSTime.set(wDate.get(Calendar.YEAR), wDate.get(Calendar.MONTH), wDate.get(Calendar.DATE), 0, 0, 0);
            wSTime.add(Calendar.SECOND, -1);

            Calendar wETime = Calendar.getInstance();
            wETime.set(wDate.get(Calendar.YEAR), wDate.get(Calendar.MONTH), wDate.get(Calendar.DATE), 23, 59, 59);

            //渲染子项
            if (wResult.Result.size() > 0) {
                wParams.put("StationDateStartTime", wSTime);
                wParams.put("StationDateEndTime", wETime);
                List<APSTaskPartPointDay> wAPSTaskPartPointDayList =
                        mAPSTaskPartPointDayService.SelectPOList(wLoginUser,
                                wParams, Pagination.getMaxSize(), wErrorCode);

                wAPSTaskPartPointDayList.sort(Comparator.comparing(APSTaskPartPointDay::getStationDate)
                        .thenComparing(APSTaskPartPointDay::getShiftType));
                //已下数量统计
                Map<Integer, Float> wPlanedMap = APSTaskPartPointDayDAO.getInstance().APS_QueryPlanedMap(
                        wResult.Result.stream().map(p -> p.TaskPartPointID).distinct().collect(Collectors.toList()),
                        wErrorCode);

                //班次列表
                FMCShiftType[] wFMCShiftTypeList = FMCShiftType.values();

                //APS
                SimpleDateFormat wSDF = new SimpleDateFormat("yyyyMMdd");
                int wDateShiftID = Integer.parseInt(wSDF.format(wDate.getTime()));
                int wTodayShiftID = Integer.parseInt(wSDF.format(Calendar.getInstance().getTime()));

                for (APSTaskPartPointDayParent wAPSTaskPartPointDayParent : wResult.Result) {
                    wAPSTaskPartPointDayParent.ItemList =
                            wAPSTaskPartPointDayList.stream().filter(p -> p.TaskPartPointID == wAPSTaskPartPointDayParent.TaskPartPointID).collect(Collectors.toList());

                    if (wAPSTaskPartPointDayParent.ItemList.size() > 0) {
                        //维护当日计划数
                        wAPSTaskPartPointDayParent.TodayPlanNum =
                                (float) wAPSTaskPartPointDayParent.ItemList.stream().mapToDouble(p -> p.PlantNum).sum();
                        //维护当日下达数
                        wAPSTaskPartPointDayParent.TodayPlanedNum =
                                (float) wAPSTaskPartPointDayParent.ItemList.stream().filter(p -> p.Status >= APSTaskStatus.Issued.getValue()).mapToDouble(p -> p.PlantNum).sum();
                        //维护当日完成数
                        wAPSTaskPartPointDayParent.TodayFinishedNum =
                                (float) wAPSTaskPartPointDayParent.ItemList.stream().mapToDouble(p -> p.ActNum).sum();
                    }

                    //总下达数赋值
                    if (wPlanedMap.containsKey(wAPSTaskPartPointDayParent.TaskPartPointID)) {
                        wAPSTaskPartPointDayParent.PlanedNum =
                                wPlanedMap.get(wAPSTaskPartPointDayParent.TaskPartPointID);
                    }
                }
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("APS_QueryDayPlanParent" + e);
        }
        return wResult;
    }

    /**
     * 翻译责任班组、负责人等信息
     */
    private void TranslateDutyInfo(BMSEmployee wLoginUser,
                                   List<APSTaskPartPointDayParent> wAPSTaskPartPointDayParentList,
                                   OutResult<Integer> wErrorCode) {
        try {
            if (wAPSTaskPartPointDayParentList == null || wAPSTaskPartPointDayParentList.size() == 0) {
                return;
            }

            //①查询班组信息
            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("Active", 1);
            List<BMSClassInfo> wBMSClassInfoList = mBMSClassInfoService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wBMSClassInfoList == null || wBMSClassInfoList.size() == 0) {
                return;
            }
            //②查询班组范围
            wParams.clear();
            wParams.put("StationActive", 1);
            List<BMSClassRange> wBMSClassRangeList = mBMSClassRangeService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(), wErrorCode);
            if (wBMSClassRangeList == null || wBMSClassRangeList.size() == 0) {
                return;
            }
            //③赋值班组信息和责任人员信息
            List<BMSClassRange> wClassRangeList;
            List<BMSClassInfo> wClassInfoList;
            List<Integer> wDutyHeadIDList;
            List<String> wDutyHeadNamesList;
            for (APSTaskPartPointDayParent wAPSTaskPartPointDayParent : wAPSTaskPartPointDayParentList) {
                for (APSTaskPartPointDay wAPSTaskPartPointDay : wAPSTaskPartPointDayParent.ItemList) {
                    TranslateClassInfo(wBMSClassInfoList, wBMSClassRangeList, wAPSTaskPartPointDay);
                }
            }
        } catch (Exception ex) {
            logger.error("TranslateDutyInfo", ex);
        }
    }

    private boolean TranslateClassInfo(List<BMSClassInfo> wBMSClassInfoList, List<BMSClassRange> wBMSClassRangeList,
                                       APSTaskPartPointDay wAPSTaskPartPointDay) {
        boolean wResult = false;
        try {
            List<BMSClassRange> wClassRangeList;
            List<String> wDutyHeadNamesList;
            List<Integer> wDutyHeadIDList;
            List<BMSClassInfo> wClassInfoList;
            //①查找所有管这个班次、工位的班组
            wClassRangeList =
                    wBMSClassRangeList.stream().filter(p -> wAPSTaskPartPointDay.StationID.stream().anyMatch(q -> q == p.StationID)
                            && p.ShiftType == wAPSTaskPartPointDay.ShiftType).collect(Collectors.toList());
            if (wClassRangeList.size() == 0) {
                return true;
            }
            //②查询班组信息
            List<Integer> wClassInfoIDList =
                    wClassRangeList.stream().map(p -> p.ClassInfoID).distinct().collect(Collectors.toList());
            wClassInfoList =
                    wBMSClassInfoList.stream().filter(p -> wClassInfoIDList.stream().anyMatch(q -> q == p.ID)).collect(Collectors.toList());
            //③赋值
            wAPSTaskPartPointDay.DutyClassIDList = wClassInfoIDList;
            wAPSTaskPartPointDay.DutyClassNames = StringUtils.Join(",",
                    wClassInfoList.stream().map(p -> p.DepartmentName).collect(Collectors.toList()));
            wDutyHeadIDList = new ArrayList<>();
            wDutyHeadNamesList = new ArrayList<>();
            for (BMSClassInfo wBMSClassInfo : wClassInfoList) {
                String[] wSplits = wBMSClassInfo.MonitorIDs.split(",");
                for (String wSplit : wSplits) {
                    int wHeadID = StringUtils.parseInt(wSplit);
                    if (wDutyHeadIDList.stream().noneMatch(p -> p == wHeadID)) {
                        wDutyHeadIDList.add(wHeadID);
                    }
                }
                String[] wSplits1 = wBMSClassInfo.MonitorList.split(",");
                for (String wSplit : wSplits1) {
                    if (wDutyHeadNamesList.stream().noneMatch(p -> p.equals(wSplit))) {
                        wDutyHeadNamesList.add(wSplit);
                    }
                }
            }
            wAPSTaskPartPointDay.DutyHeadIDList = wDutyHeadIDList;
            wAPSTaskPartPointDay.DutyHeadNames = StringUtils.Join(",", wDutyHeadNamesList);
        } catch (Exception ex) {
            logger.error("TranslateClassInfo", ex);
        }
        return false;
    }

    @Override
    public ServiceResult<List<APSTaskPartPointDayParent>> APS_QueryDispatchList(BMSEmployee wLoginUser, Map<String,
            Object> wParams, Pagination wPagination) {
        ServiceResult<List<APSTaskPartPointDayParent>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            int wOrderID = StringUtils.parseInt(wParams.get("OrderID"));
            String wRoutePartName = StringUtils.parseString(wParams.get("RoutePartName"));
            String wRoutePartPointName = StringUtils.parseString(wParams.get("RoutePartPointName"));

            wResult.Result = APSTaskPartPointDayDAO.getInstance().APS_QueryDispatchList(wOrderID, wRoutePartName,
                    wRoutePartPointName, wPagination, wErrorCode);

            //渲染子项
            if (wResult.Result.size() > 0) {
                wParams.put("TaskPartStatus", APSTaskStatus.Issued.getValue());
                wParams.put("Status", APSTaskStatus.Issued.getValue());
                List<APSTaskPartPointDay> wAPSTaskPartPointDayList =
                        mAPSTaskPartPointDayService.SelectPOList(wLoginUser, wParams, Pagination.getMaxSize(),
                                wErrorCode);
                wAPSTaskPartPointDayList.sort(Comparator.comparing(APSTaskPartPointDay::getStationDate)
                        .thenComparing(APSTaskPartPointDay::getShiftType));

                for (APSTaskPartPointDayParent wAPSTaskPartPointDayParent : wResult.Result) {
                    wAPSTaskPartPointDayParent.ItemList =
                            wAPSTaskPartPointDayList.stream().filter(p -> p.TaskPartPointID == wAPSTaskPartPointDayParent.TaskPartPointID).collect(Collectors.toList());
                }
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("APS_QueryDayPlanParent" + e);
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<APSTaskPartPointDay>> APS_QueryTaskPartPointDayAll(BMSEmployee wLoginUser, Map<String,
            Object> wParams, Pagination wPagination) {
        ServiceResult<List<APSTaskPartPointDay>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            wResult.Result = mAPSTaskPartPointDayService.SelectPOList(wLoginUser, wParams, wPagination,
                    wErrorCode);

            //①查询班组信息
            wParams.clear();
            wParams.put("Active", 1);
            List<BMSClassInfo> wBMSClassInfoList = mBMSClassInfoService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wBMSClassInfoList == null || wBMSClassInfoList.size() <= 0) {
                return wResult;
            }
            //②查询班组范围
            wParams.clear();
            wParams.put("StationActive", 1);
            List<BMSClassRange> wBMSClassRangeList = mBMSClassRangeService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(), wErrorCode);
            if (wBMSClassRangeList == null || wBMSClassRangeList.size() <= 0) {
                return wResult;
            }

            for (APSTaskPartPointDay wAPSTaskPartPointDay : wResult.Result) {
                TranslateClassInfo(wBMSClassInfoList, wBMSClassRangeList, wAPSTaskPartPointDay);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<APSTaskPartPointDay>> APS_QueryToDispatchList(BMSEmployee wLoginUser, Map<String,
            Object> wParams, Pagination wPagination) {
        ServiceResult<List<APSTaskPartPointDay>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            wPagination.setPageSize(Integer.MAX_VALUE);
            wParams.put("Status", "2,3,4");
            wParams.put("IsRepairPlan", 0);
            if (wParams.containsKey("Date")) {
                Calendar wDate = StringUtils.parseCalendar(wParams.get("Date"));
                Calendar wSTime = Calendar.getInstance();
                wSTime.set(wDate.get(Calendar.YEAR), wDate.get(Calendar.MONTH), wDate.get(Calendar.DATE), 0, 0, 0);

                Calendar wETime = Calendar.getInstance();
                wETime.set(wDate.get(Calendar.YEAR), wDate.get(Calendar.MONTH), wDate.get(Calendar.DATE), 23, 59, 59);
                wSTime.add(Calendar.SECOND, -1);
                wParams.put("StationDateStartTime", wSTime);
                wParams.put("StationDateEndTime", wETime);
            }

            List<APSTaskPartPointDay> wAPSTaskPartPointDayList = mAPSTaskPartPointDayService.SelectPOList(wLoginUser,
                    wParams, wPagination,
                    wErrorCode);

            //查询返修日计划，添加到结果中
            wParams.put("Status", "2,3,4");
            wParams.put("IsRepairPlan", 1);
            List<APSTaskPartPointDay> wRepairTaskList = mAPSTaskPartPointDayService.SelectPOList(wLoginUser,
                    wParams, Pagination.getNewMaxSize(), wErrorCode);
            if (wRepairTaskList != null && wRepairTaskList.size() > 0) {
                wAPSTaskPartPointDayList.addAll(wRepairTaskList);
            }

            if (wAPSTaskPartPointDayList != null && wAPSTaskPartPointDayList.size() > 0) {
                //①查询班组信息
                wParams.clear();
                wParams.put("Active", 1);
                List<BMSClassInfo> wBMSClassInfoList = mBMSClassInfoService.SelectPOList(wLoginUser, wParams,
                        Pagination.getNewMaxSize(),
                        wErrorCode);
                if (wBMSClassInfoList == null || wBMSClassInfoList.size() <= 0) {
                    return wResult;
                }
                //②查询班组范围
                wParams.clear();
                wParams.put("StationActive", 1);
                List<BMSClassRange> wBMSClassRangeList = mBMSClassRangeService.SelectPOList(wLoginUser, wParams,
                        Pagination.getNewMaxSize(), wErrorCode);
                if (wBMSClassRangeList == null || wBMSClassRangeList.size() <= 0) {
                    return wResult;
                }
                //判断登录人是否为班组长，若不是，则返回空
                if (wBMSClassInfoList.stream().noneMatch(p -> p.MonitorIDs.contains(String.valueOf(wLoginUser.ID)))) {
                    return wResult;
                }

                //遍历判断任务是否属于当前登录人的任务
                List<BMSClassRange> wTaskRangeList;
                List<BMSClassInfo> wTaskClassList;
                List<Integer> wMonitorIDList;
                for (APSTaskPartPointDay wAPSTaskPartPointDay : wAPSTaskPartPointDayList) {
                    wTaskRangeList =
                            wBMSClassRangeList.stream().filter(p -> wAPSTaskPartPointDay.StationID.stream().anyMatch(q -> q == p.StationID)
                                    && p.ShiftType == wAPSTaskPartPointDay.ShiftType).collect(Collectors.toList());
                    if (wTaskRangeList == null || wTaskRangeList.size() <= 0) {
                        continue;
                    }
                    //查询班组信息
                    List<Integer> wClassInfoIDList =
                            wTaskRangeList.stream().map(p -> p.ClassInfoID).distinct().collect(Collectors.toList());
                    wTaskClassList =
                            wBMSClassInfoList.stream().filter(p -> wClassInfoIDList.stream().anyMatch(q -> q == p.ID)).collect(Collectors.toList());
                    if (wTaskClassList == null || wTaskClassList.size() <= 0) {
                        continue;
                    }
                    //遍历判断登录者是否为班组长，若是，则加入返回集合
                    if (wTaskClassList.stream().anyMatch(p -> StringUtils.parseIntList(p.MonitorIDs.split(",")).stream().anyMatch(q -> q == wLoginUser.ID))) {
                        wResult.Result.add(wAPSTaskPartPointDay);
                    }
                }
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<APSTaskPartPointDay>> APS_CreateDayPlan(BMSEmployee wLoginUser, int wTaskPartPointID,
                                                                      Calendar wDate) {
        ServiceResult<List<APSTaskPartPointDay>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("ID", wTaskPartPointID);
            APSTaskPartPoint wAPSTaskPartPoint = mAPSTaskPartPointService.SelectPO(wLoginUser, wParams,
                    wErrorCode);
            if (wAPSTaskPartPoint == null || wAPSTaskPartPoint.ID <= 0) {
                wResult.FaultCode += ExceptionTypes.DBSQL.getLabel();
                return wResult;
            }

            FMCShiftType[] wFMCShiftTypeList = FMCShiftType.values();

            APSTaskPartPointDay wAPSTaskPartPointDay;
            List<Integer> wNewIDList = new ArrayList<>();
            for (FMCShiftType wFMCShiftType : wFMCShiftTypeList) {
                if (wFMCShiftType.getValue() == 0) {
                    continue;
                }

                wAPSTaskPartPointDay = new APSTaskPartPointDay();
                wAPSTaskPartPointDay.setUserInfo(wLoginUser);
                wAPSTaskPartPointDay.OrderID = wAPSTaskPartPoint.OrderID;
                wAPSTaskPartPointDay.OrderNo = wAPSTaskPartPoint.OrderNo;
                wAPSTaskPartPointDay.RoutePartID = wAPSTaskPartPoint.RoutePartID;
                wAPSTaskPartPointDay.RoutePartPointID = wAPSTaskPartPoint.RoutePartPointID;
                wAPSTaskPartPointDay.TaskPartID = wAPSTaskPartPoint.TaskPartID;
                wAPSTaskPartPointDay.WorkShopID = wAPSTaskPartPoint.WorkShopID;
                wAPSTaskPartPointDay.WorkAreaID = wAPSTaskPartPoint.WorkAreaID;
                wAPSTaskPartPointDay.StationNumMap = new HashMap<>();
                wAPSTaskPartPointDay.SetCapacityMap = new HashMap<>();
                wAPSTaskPartPointDay.StationID = wAPSTaskPartPoint.StationID;
                wAPSTaskPartPointDay.StationDate = (Calendar) wDate.clone();
                wAPSTaskPartPointDay.ShiftType = wFMCShiftType.getValue();
                wAPSTaskPartPointDay.PlantNum = 0;
                wAPSTaskPartPointDay.Status = APSTaskStatus.Saved.getValue();
                wAPSTaskPartPointDay.TaskPartPointID = wTaskPartPointID;
                wAPSTaskPartPointDay.ProductID = wAPSTaskPartPoint.ProductID;
                wAPSTaskPartPointDay.ProductNo = wAPSTaskPartPoint.ProductCode;
                int wAffectRows = mAPSTaskPartPointDayService.UpdatePo(wLoginUser, wAPSTaskPartPointDay,
                        wErrorCode);
                if (wAffectRows <= 0) {
                    wResult.FaultCode += ExceptionTypes.DBSQL.getLabel();
                    return wResult;
                }

                if (wAPSTaskPartPointDay.ID > 0) {
                    wNewIDList.add(wAPSTaskPartPointDay.ID);
                }
            }
            wParams.clear();
            wResult.Result = mAPSTaskPartPointDayService.SelectPOList(wLoginUser, wNewIDList, wParams,
                    Pagination.getNewMaxSize(), wErrorCode);
            //翻译工位
            CacheUtils.SetData(wResult.Result);

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> APS_AutoCompleteDailyPlan(BMSEmployee wLoginUser) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            TaskTimerUtils.AddTask(() ->
                            APS_AutoCompleteDailyPlan_Thread(wLoginUser, wResult), CalendarTool.getDate(),
                    CalendarTool.getDateMaxMill(), 5000, -1);
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("APS_AutoCompleteDailyPlan", e);
        }
        return wResult;
    }

    private void APS_AutoCompleteDailyPlan_Thread(BMSEmployee wLoginUser, ServiceResult<Integer> wResult) {
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            SimpleDateFormat wSDF = new SimpleDateFormat("yyyy-MM-dd");
            String wTodayKey = wSDF.format(Calendar.getInstance().getTime());

            //①查询工序计划（下达、开工）
            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("Active", 1);
            wParams.put("IsCurrent", 1);
            wParams.put("Status", "2,3,4,6");
            List<APSTaskPartPoint> wAPSTaskPartPointList = mAPSTaskPartPointService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            for (APSTaskPartPoint wAPSTaskPartPoint : wAPSTaskPartPointList) {
                if ((wAPSTaskPartPoint.PlanDayNum.size() == 0)) {
                    continue;
                }

                String wMaxKey = wAPSTaskPartPoint.PlanDayNum.keySet().stream().max(Comparator.comparing(p -> p)).get();
                //断今日是否有计划，且今日日期大于最后的日期，且有数量未完成的，补今日计划
                if (wTodayKey.compareTo(wMaxKey) > 0 && wAPSTaskPartPoint.ActNum < wAPSTaskPartPoint.PlanNum) {
                    //补今日计划
                    wAPSTaskPartPoint.PlanDayNum.put(wTodayKey,
                            new BigDecimal(wAPSTaskPartPoint.PlanNum - wAPSTaskPartPoint.ActNum)
                                    .setScale(1, RoundingMode.HALF_UP).floatValue());
                    mAPSTaskPartPointService.UpdatePo(wLoginUser, wAPSTaskPartPoint, wErrorCode);
                }
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception ex) {
            logger.error("APS_AutoCompleteDailyPlan_Thread", ex);
        }
    }

    @Override
    public ServiceResult<Integer> APS_TriggerAutoCompleteTomorrowLogic(BMSEmployee wLoginUser,
                                                                       List<APSTaskPartPointDay> wAPSTaskPartPointDayList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wAPSTaskPartPointDayList == null || wAPSTaskPartPointDayList.size() == 0) {
                return wResult;
            }

            //工序计划
            List<Integer> wIDList =
                    wAPSTaskPartPointDayList.stream().map(p -> p.TaskPartPointID).distinct().collect(Collectors.toList());

            Map<String, Object> wParams = new HashMap<String, Object>();
            List<APSTaskPartPoint> wAPSTaskPartPointList = mAPSTaskPartPointService.SelectPOList(wLoginUser, wIDList,
                    wParams, Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wAPSTaskPartPointList.size() == 0) {
                return wResult;
            }

            //明日Key
            SimpleDateFormat wSDF = new SimpleDateFormat("yyyy-MM-dd");
            Calendar wToday = Calendar.getInstance();
            wToday.add(Calendar.DATE, 1);
            String wTomorrowkey = wSDF.format(wToday.getTime());

            //工序计划分组
            Map<Integer, List<APSTaskPartPointDay>> wTaskPartPointIDDayMap = wAPSTaskPartPointDayList.stream()
                    .collect(Collectors.groupingBy(APSTaskPartPointDay::getTaskPartPointID));

            //遍历判断是否需要补明日计划（下达后是最后一天，但下达数并不能完成订单，加计划到明日）
            for (APSTaskPartPoint wAPSTaskPartPoint : wAPSTaskPartPointList) {
                //已完工计划不补
                if (wAPSTaskPartPoint.Status >= APSTaskStatus.Done.getValue()) {
                    continue;
                }

                //下达数
                List<APSTaskPartPointDay> apsTaskPartPointDays = wTaskPartPointIDDayMap.get(wAPSTaskPartPoint.ID);
                float wIssuedFQTY = (float) apsTaskPartPointDays.stream().mapToDouble(p -> p.PlantNum).sum();

                String wMaxKey = wAPSTaskPartPoint.PlanDayNum.keySet().stream().max(Comparator.comparing(p -> p)).get();
                if (wTomorrowkey.compareTo(wMaxKey) > 0 && wIssuedFQTY + wAPSTaskPartPoint.ActNum < wAPSTaskPartPoint.PlanNum) {
                    float wPlantNum = new BigDecimal(wAPSTaskPartPoint.PlanNum - wAPSTaskPartPoint.ActNum - wIssuedFQTY)
                            .setScale(1, RoundingMode.HALF_UP).floatValue();
                    wAPSTaskPartPoint.PlanDayNum.put(wTomorrowkey, wPlantNum);
                    mAPSTaskPartPointService.UpdatePo(wLoginUser, wAPSTaskPartPoint, wErrorCode);
                }
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<APSTaskPartPointDayParent>> APS_QueryDayPlanParent_V1(BMSEmployee wLoginUser,
                                                                                    Map<String, Object> wParams,
                                                                                    Calendar wDate,
                                                                                    Pagination wPagination) {
        ServiceResult<List<APSTaskPartPointDayParent>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            //①查询当前版本的工序计划（下达、开工）
            wParams.put("Active", 1);
            wParams.put("IsCurrent", 1);
            wParams.put("Status", StringUtils.Join(",", new ArrayList<>(Arrays.asList(APSTaskStatus.Issued.getValue(),
                    APSTaskStatus.Confirm.getValue(), APSTaskStatus.Started.getValue(),
                    APSTaskStatus.Suspend.getValue()))));
            List<APSTaskPartPoint> wAPSTaskPartPointList = mAPSTaskPartPointService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wAPSTaskPartPointList == null || wAPSTaskPartPointList.size() <= 0) {
                return wResult;
            }
            //②判断工序详情中是否包含今日计划
            SimpleDateFormat wSDF = new SimpleDateFormat("yyyy-MM-dd");
            String wTodayKey = wSDF.format(wDate.getTime());
            wAPSTaskPartPointList =
                    wAPSTaskPartPointList.stream().filter(p -> p.PlanDayNum.containsKey(wTodayKey)).collect(Collectors.toList());
            if (wAPSTaskPartPointList.size() == 0) {
                return wResult;
            }
            List<Integer> wAPSTaskPartPointIDList =
                    wAPSTaskPartPointList.stream().map(p -> p.ID).collect(Collectors.toList());

            //查询周计划
            List<Integer> wTaskPartIDList =
                    wAPSTaskPartPointList.stream().map(p -> p.TaskPartID).distinct().collect(Collectors.toList());
            wParams.clear();
            List<APSTaskPart> wAPSTaskPartList = mAPSTaskPartService.SelectPOList(wLoginUser, wTaskPartIDList, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wAPSTaskPartList == null || wAPSTaskPartList.size() <= 0) {
                return wResult;
            }
            Map<Integer, APSTaskPart> wIDTaskPartMap =
                    wAPSTaskPartList.stream().collect(Collectors.toMap(APSTaskPart::getID
                            , p -> p));
            //查询工序日计划
            wParams.clear();
            wParams.put("TaskPartID", StringUtils.Join(",", wTaskPartIDList));
            wParams.put("Status", StringUtils.Join(",", new ArrayList<>(Arrays.asList(APSTaskStatus.Saved.getValue(),
                    APSTaskStatus.Issued.getValue(),
                    APSTaskStatus.Confirm.getValue(), APSTaskStatus.Started.getValue(), APSTaskStatus.Done.getValue(),
                    APSTaskStatus.Suspend.getValue()))));
            wParams.put("IsRepairPlan", 0);
            List<APSTaskPartPointDay> wAPSTaskPartPointDayList = mAPSTaskPartPointDayService.SelectPOList(wLoginUser,
                    wParams, Pagination.getNewMaxSize(),
                    wErrorCode);
            Map<Integer, List<APSTaskPartPointDay>> wTaskPartIDTaskPartPointMap = wAPSTaskPartPointDayList.stream()
                    .collect(Collectors.groupingBy(APSTaskPartPointDay::getTaskPartID));

            //③整理返回数据
            APSTaskPartPointDayParent wAPSTaskPartPointDayParent;
            for (APSTaskPartPoint wAPSTaskPartPoint : wAPSTaskPartPointList) {
                wAPSTaskPartPointDayParent = new APSTaskPartPointDayParent();
                wAPSTaskPartPointDayParent.OrderID = wAPSTaskPartPoint.OrderID;
                wAPSTaskPartPointDayParent.OrderNo = wAPSTaskPartPoint.OrderNo;
                wAPSTaskPartPointDayParent.RoutePartID = wAPSTaskPartPoint.RoutePartID;
                wAPSTaskPartPointDayParent.RoutePartName = wAPSTaskPartPoint.RoutePartName;
                wAPSTaskPartPointDayParent.RoutePartOrder = wAPSTaskPartPoint.RoutePartOrder;
                wAPSTaskPartPointDayParent.RoutePartPointID = wAPSTaskPartPoint.RoutePartPointID;
                wAPSTaskPartPointDayParent.RoutePartPointName = wAPSTaskPartPoint.RoutePartPointName;
                wAPSTaskPartPointDayParent.RoutePartPointOrder = wAPSTaskPartPoint.RoutePartPointOrder;
                wAPSTaskPartPointDayParent.TaskPartID = wAPSTaskPartPoint.TaskPartID;
                wAPSTaskPartPointDayParent.TaskPartStatus = wIDTaskPartMap.get(wAPSTaskPartPoint.TaskPartID).Status;
                wAPSTaskPartPointDayParent.TaskPartPointID = wAPSTaskPartPoint.ID;
                wAPSTaskPartPointDayParent.PlanNum = wAPSTaskPartPoint.PlanNum;
                //四舍五入，保留2位小数
                wAPSTaskPartPointDayParent.FinishedNum = StringUtils.numberHalfUp(wAPSTaskPartPoint.ActNum, 2);
                wAPSTaskPartPointDayParent.TodayPlanNum = wAPSTaskPartPoint.PlanDayNum.get(wTodayKey);
                //今日下达数、今日完成数
                if (wTaskPartIDTaskPartPointMap.containsKey(wAPSTaskPartPoint.TaskPartID)) {
                    List<APSTaskPartPointDay> apsTaskPartPointDays =
                            wTaskPartIDTaskPartPointMap.get(wAPSTaskPartPoint.TaskPartID);
                    apsTaskPartPointDays =
                            apsTaskPartPointDays.stream().filter(p -> p.RoutePartPointID == wAPSTaskPartPoint.RoutePartPointID).collect(Collectors.toList());
                    Map<String, List<APSTaskPartPointDay>> wTodayMap = apsTaskPartPointDays.stream()
                            .collect(Collectors.groupingBy(k -> wSDF.format(k.StationDate.getTime())));
                    if (wTodayMap.containsKey(wTodayKey)) {
                        List<APSTaskPartPointDay> apsTaskPartPointDays1 = wTodayMap.get(wTodayKey);
                        wAPSTaskPartPointDayParent.TodayPlanedNum =
                                (float) apsTaskPartPointDays1.stream().mapToDouble(p -> p.PlantNum).sum();
                        wAPSTaskPartPointDayParent.TodayFinishedNum =
                                (float) apsTaskPartPointDays1.stream().mapToDouble(p -> p.ActNum).sum();
                        //四舍五入，保留2位小数
                        wAPSTaskPartPointDayParent.TodayFinishedNum =
                                StringUtils.numberHalfUp(wAPSTaskPartPointDayParent.TodayFinishedNum, 2);
                        wAPSTaskPartPointDayParent.ItemList = apsTaskPartPointDays1;
                    }
                }

                wResult.Result.add(wAPSTaskPartPointDayParent);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("APS_QueryDayPlanParent_V1", e);
        }
        return wResult;
    }
    //endregion

    //region 计划相关

    @Override
    public ServiceResult<Integer> APS_MonthlyPlanImport(BMSEmployee wLoginUser, ExcelData wExcelData) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelData == null || wExcelData.sheetData == null || wExcelData.sheetData.size() <= 0) {
                wResult.FaultCode += "导入失败：Excel格式错误!!!";
                return wResult;
            }

            ExcelSheetData wExcelSheetData = wExcelData.sheetData.get(0);
            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                wResult.FaultCode += "导入失败：Excel无内容!!!";
                return wResult;
            }

            //①订单数据
            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("Status", "2,3,4");
            List<OMSOrder> wOMSOrderList = mOMSOrderService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wOMSOrderList == null || wOMSOrderList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到可导入的订单信息!!!";
                return wResult;
            }
            Map<String, Integer> wCodeRouteIDOrderMap =
                    wOMSOrderList.stream().collect(Collectors.toMap(OMSOrder::getCode
                            , OMSOrder::getRouteID));
            Map<String, Integer> wCodeIDOrderMap =
                    wOMSOrderList.stream().collect(Collectors.toMap(OMSOrder::getCode
                            , OMSOrder::getID));

            //②订单工艺数据
            List<Integer> wRouteIDList =
                    wOMSOrderList.stream().map(p -> p.RouteID).distinct().collect(Collectors.toList());
            wParams.clear();
            wParams.put("RouteID", StringUtils.Join(",", wRouteIDList));
            wParams.put("Active", 1);
            List<FPCRoutePart> wFPCRoutePartList = mFPCRoutePartService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wFPCRoutePartList == null || wFPCRoutePartList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到订单工艺信息!!!";
                return wResult;
            }

            Map<Integer, Map<String, Integer>> wRouteIDRoutePartNameIDMap = new HashMap<>();
            List<FPCRoutePart> wTempList;
            for (int wRouteID : wRouteIDList) {
                wTempList =
                        wFPCRoutePartList.stream().filter(p -> p.RouteID == wRouteID).collect(Collectors.toList());
                Map<String, Integer> wTempMap =
                        wTempList.stream().collect(Collectors.toMap(FPCRoutePart::getName
                                , FPCRoutePart::getID));
                wRouteIDRoutePartNameIDMap.put(wRouteID, wTempMap);
            }

            Calendar wBaseTime = Calendar.getInstance();
            wBaseTime.set(2010, 0, 1, 0, 0, 0);

            SimpleDateFormat wSDF = new SimpleDateFormat("yyyy-MM-dd");

            Calendar wTodayTime = Calendar.getInstance();
            wTodayTime.set(Calendar.HOUR_OF_DAY, 0);
            wTodayTime.set(Calendar.MINUTE, 0);
            wTodayTime.set(Calendar.SECOND, 0);
            wTodayTime.add(Calendar.SECOND, -1);

            List<APSMonthImpPo> wAPSMonthImpPoList = new ArrayList<>();
            APSMonthImpPo wAPSMonthImpPo;
            List<Integer> wOrderIDList = new ArrayList<>();
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                if (i == 0) {
                    continue;
                }

                ExcelLineData wExcelLineData = wExcelSheetData.lineData.get(i);
                int wIndex = 0;

                //开始日期
                String wCol1 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol1)) {
                    continue;
                }
                Calendar wStartDate = StringUtils.parseCalendar(wCol1);
                if (wStartDate.compareTo(wBaseTime) <= 0) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，开始日期输入值【{1}】不合法!!!", i + 1, wCol1);
                    return wResult;
                }
                if (wStartDate.compareTo(wTodayTime) < 0) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，开始日期【{1}】小于当前日期!!!", i + 1,
                            wSDF.format(wStartDate.getTime()));
                    return wResult;
                }
                //订单号
                String wCol2 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wCodeRouteIDOrderMap.containsKey(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号【{1}】不存在或订单状态不满足导入要求!!!", i + 1,
                            wCol2);
                    return wResult;
                }
                int wRouteID = wCodeRouteIDOrderMap.get(wCol2);
                if (!wRouteIDRoutePartNameIDMap.containsKey(wRouteID)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号【{1}】工艺路线不存在!!!", i + 1,
                            wCol2);
                    return wResult;
                }

                wOrderIDList.add(wCodeIDOrderMap.get(wCol2));

                Map<String, Integer> wRouteNameMap = wRouteIDRoutePartNameIDMap.get(wRouteID);
                //卷制工艺
                String wRouteName_1 = wExcelSheetData.lineData.get(0).colData.get(wIndex);
//                if (!wRouteNameMap.containsKey(wRouteName_1)) {
//                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号【{1}】中工艺【{2}】不存在!!!", i + 1,
//                            wCol2, wRouteName_1);
//                    return wResult;
//                }
                String wCol3 = wExcelLineData.colData.get(wIndex++);
                float wFQTY_1 = StringUtils.parseFloat(wCol3);
                //定型工艺
                String wRouteName_2 = wExcelSheetData.lineData.get(0).colData.get(wIndex);
//                if (!wRouteNameMap.containsKey(wRouteName_2)) {
//                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号【{1}】中工艺【{2}】不存在!!!", i + 1,
//                            wCol2, wRouteName_2);
//                    return wResult;
//                }
                String wCol4 = wExcelLineData.colData.get(wIndex++);
                //喷金工艺
                String wRouteName_3 = wExcelSheetData.lineData.get(0).colData.get(wIndex);
//                if (!wRouteNameMap.containsKey(wRouteName_3)) {
//                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号【{1}】中工艺【{2}】不存在!!!", i + 1,
//                            wCol2, wRouteName_3);
//                    return wResult;
//                }
                String wCol5 = wExcelLineData.colData.get(wIndex++);
                //赋能工艺
                String wRouteName_4 = wExcelSheetData.lineData.get(0).colData.get(wIndex);
//                if (!wRouteNameMap.containsKey(wRouteName_4)) {
//                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号【{1}】中工艺【{2}】不存在!!!", i + 1,
//                            wCol2, wRouteName_4);
//                    return wResult;
//                }
                String wCol6 = wExcelLineData.colData.get(wIndex++);
                //芯子工艺
                String wRouteName_5 = wExcelSheetData.lineData.get(0).colData.get(wIndex);
//                if (!wRouteNameMap.containsKey(wRouteName_5)) {
//                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号【{1}】中工艺【{2}】不存在!!!", i + 1,
//                            wCol2, wRouteName_5);
//                    return wResult;
//                }
                String wCol7 = wExcelLineData.colData.get(wIndex++);
                //真空注胶工艺
                String wRouteName_6 = wExcelSheetData.lineData.get(0).colData.get(wIndex);
//                if (!wRouteNameMap.containsKey(wRouteName_6)) {
//                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号【{1}】中工艺【{2}】不存在!!!", i + 1,
//                            wCol2, wRouteName_6);
//                    return wResult;
//                }
                String wCol8 = wExcelLineData.colData.get(wIndex++);
                //试验工艺
                String wRouteName_7 = wExcelSheetData.lineData.get(0).colData.get(wIndex);
//                if (!wRouteNameMap.containsKey(wRouteName_7)) {
//                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号【{1}】中工艺【{2}】不存在!!!", i + 1,
//                            wCol2, wRouteName_7);
//                    return wResult;
//                }
                String wCol9 = wExcelLineData.colData.get(wIndex++);
                //成品装箱工艺
                String wRouteName_8 = wExcelSheetData.lineData.get(0).colData.get(wIndex);
//                if (!wRouteNameMap.containsKey(wRouteName_8)) {
//                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号【{1}】中工艺【{2}】不存在!!!", i + 1,
//                            wCol2, wRouteName_8);
//                    return wResult;
//                }
                String wCol10 = wExcelLineData.colData.get(wIndex++);

                wAPSMonthImpPo = new APSMonthImpPo();
                wAPSMonthImpPo.StartDate = wStartDate;
                wAPSMonthImpPo.OrderNo = wCol2;
                wAPSMonthImpPo.FQTY_1 = StringUtils.parseFloat(wCol3);
                wAPSMonthImpPo.RouteName_1 = wRouteName_1;
                wAPSMonthImpPo.FQTY_2 = StringUtils.parseFloat(wCol4);
                wAPSMonthImpPo.RouteName_2 = wRouteName_2;
                wAPSMonthImpPo.FQTY_3 = StringUtils.parseFloat(wCol5);
                wAPSMonthImpPo.RouteName_3 = wRouteName_3;
                wAPSMonthImpPo.FQTY_4 = StringUtils.parseFloat(wCol6);
                wAPSMonthImpPo.RouteName_4 = wRouteName_4;
                wAPSMonthImpPo.FQTY_5 = StringUtils.parseFloat(wCol7);
                wAPSMonthImpPo.RouteName_5 = wRouteName_5;
                wAPSMonthImpPo.FQTY_6 = StringUtils.parseFloat(wCol8);
                wAPSMonthImpPo.RouteName_6 = wRouteName_6;
                wAPSMonthImpPo.FQTY_7 = StringUtils.parseFloat(wCol9);
                wAPSMonthImpPo.RouteName_7 = wRouteName_7;
                wAPSMonthImpPo.FQTY_8 = StringUtils.parseFloat(wCol10);
                wAPSMonthImpPo.RouteName_8 = wRouteName_8;

                //补齐计划数量数据
                AutoCaclPlanNumber(wAPSMonthImpPo, wExcelLineData);

                wAPSMonthImpPoList.add(wAPSMonthImpPo);
            }

            wOrderIDList = wOrderIDList.stream().distinct().collect(Collectors.toList());

            //查询已制定的所有的计划
            wParams.clear();
            wParams.put("OrderID", StringUtils.Join(",", wOrderIDList));
            wParams.put("ShiftPeriod", APSShiftPeriod.Month.getValue());
            wParams.put("Active", 1);
            List<APSTaskPart> wAPSTaskPartList = mAPSTaskPartService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            String wMsg = CheckPlanNumber(wAPSTaskPartList, wAPSMonthImpPoList, wOrderIDList, wOMSOrderList,
                    wRouteIDRoutePartNameIDMap);
            if (StringUtils.isNotEmpty(wMsg)) {
                wResult.FaultCode += wMsg;
                return wResult;
            }

            //创建新计划
            List<APSTaskPart> wNewTaskList = APS_GetNewMonthTask(wAPSMonthImpPoList, wOrderIDList, wOMSOrderList,
                    wFPCRoutePartList, wAPSTaskPartList);
            //调用保存接口，保存新计划
            if (wNewTaskList != null && wNewTaskList.size() > 0) {
                wResult = ASVServiceImpl.getInstance().APS_SaveSchedulingVersion(wLoginUser, wNewTaskList,
                        APSShiftPeriod.Month.getValue());
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("APS_MonthlyPlanImport", e);
        }
        return wResult;
    }

    /**
     * 转化为月计划数据
     */
    private List<APSTaskPart> APS_GetNewMonthTask(List<APSMonthImpPo> wAPSMonthImpPoList, List<Integer> wOrderIDList,
                                                  List<OMSOrder> wOMSOrderList, List<FPCRoutePart> wFPCRoutePartList,
                                                  List<APSTaskPart> wAPSTaskPartList) {
        List<APSTaskPart> wResult = new ArrayList<>();
        try {
            Map<Integer, Integer> wIDRouteIDOrderMap =
                    wOMSOrderList.stream().collect(Collectors.toMap(OMSOrder::getID
                            , OMSOrder::getRouteID));
            Map<Integer, OMSOrder> wIDOrderMap =
                    wOMSOrderList.stream().collect(Collectors.toMap(OMSOrder::getID
                            , p -> p));

            SimpleDateFormat wSDF = new SimpleDateFormat("yyyyMMdd");
            int wToday = StringUtils.parseInt(wSDF.format(Calendar.getInstance().getTime()));

            APSTaskPart wAPSTaskPart;
            for (int wOrderID : wOrderIDList) {
                int wRouteID = wIDRouteIDOrderMap.get(wOrderID);
                List<FPCRoutePart> wOrderRoutePartList =
                        wFPCRoutePartList.stream().filter(p -> p.RouteID == wRouteID).collect(Collectors.toList());
                //卷制
                if (wOrderRoutePartList.stream().anyMatch(p -> p.Name.equals("卷制工艺"))) {
                    wResult.add(getApsTaskPart1(wAPSMonthImpPoList, wAPSTaskPartList, wIDOrderMap, wSDF, wToday,
                            wOrderID, wOrderRoutePartList));
                }
                //定型
                if (wOrderRoutePartList.stream().anyMatch(p -> p.Name.equals("定型工艺"))) {
                    wResult.add(getApsTaskPart2(wAPSMonthImpPoList, wAPSTaskPartList, wIDOrderMap, wSDF, wToday,
                            wOrderID, wOrderRoutePartList));
                }
                //喷金
                if (wOrderRoutePartList.stream().anyMatch(p -> p.Name.equals("喷金工艺"))) {
                    wResult.add(getApsTaskPart3(wAPSMonthImpPoList, wAPSTaskPartList, wIDOrderMap, wSDF, wToday,
                            wOrderID, wOrderRoutePartList));
                }
                //赋能
                if (wOrderRoutePartList.stream().anyMatch(p -> p.Name.equals("赋能工艺"))) {
                    wResult.add(getApsTaskPart4(wAPSMonthImpPoList, wAPSTaskPartList, wIDOrderMap, wSDF, wToday,
                            wOrderID, wOrderRoutePartList));
                }
                //芯子
                if (wOrderRoutePartList.stream().anyMatch(p -> p.Name.equals("芯子工艺"))) {
                    wResult.add(getApsTaskPart5(wAPSMonthImpPoList, wAPSTaskPartList, wIDOrderMap, wSDF, wToday,
                            wOrderID, wOrderRoutePartList));
                }
                //真空注胶工艺
                if (wOrderRoutePartList.stream().anyMatch(p -> p.Name.equals("真空注胶工艺"))) {
                    wResult.add(getApsTaskPart6(wAPSMonthImpPoList, wAPSTaskPartList, wIDOrderMap, wSDF, wToday,
                            wOrderID, wOrderRoutePartList));
                }
                //试验工艺
                if (wOrderRoutePartList.stream().anyMatch(p -> p.Name.equals("试验工艺"))) {
                    wResult.add(getApsTaskPart7(wAPSMonthImpPoList, wAPSTaskPartList, wIDOrderMap, wSDF, wToday,
                            wOrderID, wOrderRoutePartList));
                }
                //成品装箱工艺
                if (wOrderRoutePartList.stream().anyMatch(p -> p.Name.equals("成品装箱工艺"))) {
                    wResult.add(getApsTaskPart8(wAPSMonthImpPoList, wAPSTaskPartList, wIDOrderMap, wSDF, wToday,
                            wOrderID, wOrderRoutePartList));
                }
            }

            //统一处理开始日期和结束日期
            for (APSTaskPart wAPSTaskPartItem : wResult) {
                List<String> wDateStrList =
                        wAPSTaskPartItem.PlanDayNum.keySet().stream().sorted(Comparator.comparing(p -> p)).collect(Collectors.toList());
                wAPSTaskPartItem.PartStartTime = StringUtils.parseCalendar(wDateStrList.get(0));
                wAPSTaskPartItem.PartEndTime = StringUtils.parseCalendar(wDateStrList.get(wDateStrList.size() - 1));
            }
        } catch (Exception e) {
            logger.error("APS_GetNewMonthTask", e);
        }
        return wResult;
    }

    //region 创建月计划
    private APSTaskPart getApsTaskPart1(List<APSMonthImpPo> wAPSMonthImpPoList, List<APSTaskPart> wAPSTaskPartList,
                                        Map<Integer, OMSOrder> wIDOrderMap, SimpleDateFormat wSDF, int wToday,
                                        int wOrderID, List<FPCRoutePart> wOrderRoutePartList) {
        APSTaskPart wAPSTaskPart = new APSTaskPart();
        try {
            SimpleDateFormat wSDF1 = new SimpleDateFormat("yyyy-MM-dd");
            if (wAPSTaskPartList.stream().anyMatch(p -> p.RoutePartName.equals("卷制工艺") && p.OrderID == wOrderID)) {
                wAPSTaskPart =
                        wAPSTaskPartList.stream().filter(p -> p.RoutePartName.equals("卷制工艺") && p.OrderID == wOrderID).findFirst().get();
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                for (String wDateStr : wAPSTaskPart.PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wPlanDayNumMap.put(wDateStr, wAPSTaskPart.PlanDayNum.get(wDateStr));
                    }
                }
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_1 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_1);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ID = 0;
                wAPSTaskPart.Code = "";
                wAPSTaskPart.PlantNum = wIDOrderMap.get(wOrderID).FQTYPlan;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            } else {
                FPCRoutePart wFPCRoutePart =
                        wOrderRoutePartList.stream().filter(p -> p.Name.equals("卷制工艺")).findFirst().get();
                wAPSTaskPart = new APSTaskPart(wFPCRoutePart, wIDOrderMap.get(wOrderID));
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_1 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_1);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ShiftPeriod = APSShiftPeriod.Month.getValue();
                wAPSTaskPart.PartStartTime =
                        wList.stream().min(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            }
        } catch (Exception ex) {
            logger.error("getApsTaskPart1", ex);
        }

        return wAPSTaskPart;
    }

    private APSTaskPart getApsTaskPart2(List<APSMonthImpPo> wAPSMonthImpPoList, List<APSTaskPart> wAPSTaskPartList,
                                        Map<Integer, OMSOrder> wIDOrderMap, SimpleDateFormat wSDF, int wToday,
                                        int wOrderID, List<FPCRoutePart> wOrderRoutePartList) {
        APSTaskPart wAPSTaskPart = new APSTaskPart();
        try {
            SimpleDateFormat wSDF1 = new SimpleDateFormat("yyyy-MM-dd");
            if (wAPSTaskPartList.stream().anyMatch(p -> p.RoutePartName.equals("定型工艺") && p.OrderID == wOrderID)) {
                wAPSTaskPart =
                        wAPSTaskPartList.stream().filter(p -> p.RoutePartName.equals("定型工艺") && p.OrderID == wOrderID).findFirst().get();
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                for (String wDateStr : wAPSTaskPart.PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wPlanDayNumMap.put(wDateStr, wAPSTaskPart.PlanDayNum.get(wDateStr));
                    }
                }
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_2 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_2);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ID = 0;
                wAPSTaskPart.Code = "";
                wAPSTaskPart.PlantNum = wIDOrderMap.get(wOrderID).FQTYPlan;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            } else {
                FPCRoutePart wFPCRoutePart =
                        wOrderRoutePartList.stream().filter(p -> p.Name.equals("定型工艺")).findFirst().get();
                wAPSTaskPart = new APSTaskPart(wFPCRoutePart, wIDOrderMap.get(wOrderID));
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_2 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_2);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ShiftPeriod = APSShiftPeriod.Month.getValue();
                wAPSTaskPart.PartStartTime =
                        wList.stream().min(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            }
        } catch (Exception ex) {
            logger.error("getApsTaskPart2", ex);
        }

        return wAPSTaskPart;
    }

    private APSTaskPart getApsTaskPart3(List<APSMonthImpPo> wAPSMonthImpPoList, List<APSTaskPart> wAPSTaskPartList,
                                        Map<Integer, OMSOrder> wIDOrderMap, SimpleDateFormat wSDF, int wToday,
                                        int wOrderID, List<FPCRoutePart> wOrderRoutePartList) {
        APSTaskPart wAPSTaskPart = new APSTaskPart();
        try {
            SimpleDateFormat wSDF1 = new SimpleDateFormat("yyyy-MM-dd");
            if (wAPSTaskPartList.stream().anyMatch(p -> p.RoutePartName.equals("喷金工艺") && p.OrderID == wOrderID)) {
                wAPSTaskPart =
                        wAPSTaskPartList.stream().filter(p -> p.RoutePartName.equals("喷金工艺") && p.OrderID == wOrderID).findFirst().get();
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                for (String wDateStr : wAPSTaskPart.PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wPlanDayNumMap.put(wDateStr, wAPSTaskPart.PlanDayNum.get(wDateStr));
                    }
                }
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_3 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_3);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ID = 0;
                wAPSTaskPart.Code = "";
                wAPSTaskPart.PlantNum = wIDOrderMap.get(wOrderID).FQTYPlan;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            } else {
                FPCRoutePart wFPCRoutePart =
                        wOrderRoutePartList.stream().filter(p -> p.Name.equals("喷金工艺")).findFirst().get();
                wAPSTaskPart = new APSTaskPart(wFPCRoutePart, wIDOrderMap.get(wOrderID));
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_3 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_3);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ShiftPeriod = APSShiftPeriod.Month.getValue();
                wAPSTaskPart.PartStartTime =
                        wList.stream().min(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            }
        } catch (Exception ex) {
            logger.error("getApsTaskPart3", ex);
        }

        return wAPSTaskPart;
    }

    private APSTaskPart getApsTaskPart4(List<APSMonthImpPo> wAPSMonthImpPoList, List<APSTaskPart> wAPSTaskPartList,
                                        Map<Integer, OMSOrder> wIDOrderMap, SimpleDateFormat wSDF, int wToday,
                                        int wOrderID, List<FPCRoutePart> wOrderRoutePartList) {
        APSTaskPart wAPSTaskPart = new APSTaskPart();
        try {
            SimpleDateFormat wSDF1 = new SimpleDateFormat("yyyy-MM-dd");
            if (wAPSTaskPartList.stream().anyMatch(p -> p.RoutePartName.equals("赋能工艺") && p.OrderID == wOrderID)) {
                wAPSTaskPart =
                        wAPSTaskPartList.stream().filter(p -> p.RoutePartName.equals("赋能工艺") && p.OrderID == wOrderID).findFirst().get();
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                for (String wDateStr : wAPSTaskPart.PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wPlanDayNumMap.put(wDateStr, wAPSTaskPart.PlanDayNum.get(wDateStr));
                    }
                }
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_4 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_4);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ID = 0;
                wAPSTaskPart.Code = "";
                wAPSTaskPart.PlantNum = wIDOrderMap.get(wOrderID).FQTYPlan;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            } else {
                FPCRoutePart wFPCRoutePart =
                        wOrderRoutePartList.stream().filter(p -> p.Name.equals("赋能工艺")).findFirst().get();
                wAPSTaskPart = new APSTaskPart(wFPCRoutePart, wIDOrderMap.get(wOrderID));
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_4 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_4);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ShiftPeriod = APSShiftPeriod.Month.getValue();
                wAPSTaskPart.PartStartTime =
                        wList.stream().min(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            }
        } catch (Exception ex) {
            logger.error("getApsTaskPart4", ex);
        }

        return wAPSTaskPart;
    }

    private APSTaskPart getApsTaskPart5(List<APSMonthImpPo> wAPSMonthImpPoList, List<APSTaskPart> wAPSTaskPartList,
                                        Map<Integer, OMSOrder> wIDOrderMap, SimpleDateFormat wSDF, int wToday,
                                        int wOrderID, List<FPCRoutePart> wOrderRoutePartList) {
        APSTaskPart wAPSTaskPart = new APSTaskPart();
        try {
            SimpleDateFormat wSDF1 = new SimpleDateFormat("yyyy-MM-dd");
            if (wAPSTaskPartList.stream().anyMatch(p -> p.RoutePartName.equals("芯子工艺") && p.OrderID == wOrderID)) {
                wAPSTaskPart =
                        wAPSTaskPartList.stream().filter(p -> p.RoutePartName.equals("芯子工艺") && p.OrderID == wOrderID).findFirst().get();
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                for (String wDateStr : wAPSTaskPart.PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wPlanDayNumMap.put(wDateStr, wAPSTaskPart.PlanDayNum.get(wDateStr));
                    }
                }
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_5 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_5);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ID = 0;
                wAPSTaskPart.Code = "";
                wAPSTaskPart.PlantNum = wIDOrderMap.get(wOrderID).FQTYPlan;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            } else {
                FPCRoutePart wFPCRoutePart =
                        wOrderRoutePartList.stream().filter(p -> p.Name.equals("芯子工艺")).findFirst().get();
                wAPSTaskPart = new APSTaskPart(wFPCRoutePart, wIDOrderMap.get(wOrderID));
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_5 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_5);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ShiftPeriod = APSShiftPeriod.Month.getValue();
                wAPSTaskPart.PartStartTime =
                        wList.stream().min(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            }
        } catch (Exception ex) {
            logger.error("getApsTaskPart5", ex);
        }

        return wAPSTaskPart;
    }

    private APSTaskPart getApsTaskPart6(List<APSMonthImpPo> wAPSMonthImpPoList, List<APSTaskPart> wAPSTaskPartList,
                                        Map<Integer, OMSOrder> wIDOrderMap, SimpleDateFormat wSDF, int wToday,
                                        int wOrderID, List<FPCRoutePart> wOrderRoutePartList) {
        APSTaskPart wAPSTaskPart = new APSTaskPart();
        try {
            SimpleDateFormat wSDF1 = new SimpleDateFormat("yyyy-MM-dd");
            if (wAPSTaskPartList.stream().anyMatch(p -> p.RoutePartName.equals("真空注胶工艺") && p.OrderID == wOrderID)) {
                wAPSTaskPart =
                        wAPSTaskPartList.stream().filter(p -> p.RoutePartName.equals("真空注胶工艺") && p.OrderID == wOrderID).findFirst().get();
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                for (String wDateStr : wAPSTaskPart.PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wPlanDayNumMap.put(wDateStr, wAPSTaskPart.PlanDayNum.get(wDateStr));
                    }
                }
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_6 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_6);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ID = 0;
                wAPSTaskPart.Code = "";
                wAPSTaskPart.PlantNum = wIDOrderMap.get(wOrderID).FQTYPlan;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            } else {
                FPCRoutePart wFPCRoutePart =
                        wOrderRoutePartList.stream().filter(p -> p.Name.equals("真空注胶工艺")).findFirst().get();
                wAPSTaskPart = new APSTaskPart(wFPCRoutePart, wIDOrderMap.get(wOrderID));
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_6 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_6);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ShiftPeriod = APSShiftPeriod.Month.getValue();
                wAPSTaskPart.PartStartTime =
                        wList.stream().min(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            }
        } catch (Exception ex) {
            logger.error("getApsTaskPart6", ex);
        }

        return wAPSTaskPart;
    }

    private APSTaskPart getApsTaskPart7(List<APSMonthImpPo> wAPSMonthImpPoList, List<APSTaskPart> wAPSTaskPartList,
                                        Map<Integer, OMSOrder> wIDOrderMap, SimpleDateFormat wSDF, int wToday,
                                        int wOrderID, List<FPCRoutePart> wOrderRoutePartList) {
        APSTaskPart wAPSTaskPart = new APSTaskPart();
        try {
            SimpleDateFormat wSDF1 = new SimpleDateFormat("yyyy-MM-dd");
            if (wAPSTaskPartList.stream().anyMatch(p -> p.RoutePartName.equals("试验工艺") && p.OrderID == wOrderID)) {
                wAPSTaskPart =
                        wAPSTaskPartList.stream().filter(p -> p.RoutePartName.equals("试验工艺") && p.OrderID == wOrderID).findFirst().get();
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                for (String wDateStr : wAPSTaskPart.PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wPlanDayNumMap.put(wDateStr, wAPSTaskPart.PlanDayNum.get(wDateStr));
                    }
                }
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_7 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_7);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ID = 0;
                wAPSTaskPart.Code = "";
                wAPSTaskPart.PlantNum = wIDOrderMap.get(wOrderID).FQTYPlan;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            } else {
                FPCRoutePart wFPCRoutePart =
                        wOrderRoutePartList.stream().filter(p -> p.Name.equals("试验工艺")).findFirst().get();
                wAPSTaskPart = new APSTaskPart(wFPCRoutePart, wIDOrderMap.get(wOrderID));
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_7 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_7);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ShiftPeriod = APSShiftPeriod.Month.getValue();
                wAPSTaskPart.PartStartTime =
                        wList.stream().min(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            }
        } catch (Exception ex) {
            logger.error("getApsTaskPart7", ex);
        }

        return wAPSTaskPart;
    }

    private APSTaskPart getApsTaskPart8(List<APSMonthImpPo> wAPSMonthImpPoList, List<APSTaskPart> wAPSTaskPartList,
                                        Map<Integer, OMSOrder> wIDOrderMap, SimpleDateFormat wSDF, int wToday,
                                        int wOrderID, List<FPCRoutePart> wOrderRoutePartList) {
        APSTaskPart wAPSTaskPart = new APSTaskPart();
        try {
            SimpleDateFormat wSDF1 = new SimpleDateFormat("yyyy-MM-dd");
            if (wAPSTaskPartList.stream().anyMatch(p -> p.RoutePartName.equals("成品装箱工艺") && p.OrderID == wOrderID)) {
                wAPSTaskPart =
                        wAPSTaskPartList.stream().filter(p -> p.RoutePartName.equals("成品装箱工艺") && p.OrderID == wOrderID).findFirst().get();
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                for (String wDateStr : wAPSTaskPart.PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wPlanDayNumMap.put(wDateStr, wAPSTaskPart.PlanDayNum.get(wDateStr));
                    }
                }
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_8 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_8);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ID = 0;
                wAPSTaskPart.Code = "";
                wAPSTaskPart.PlantNum = wIDOrderMap.get(wOrderID).FQTYPlan;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            } else {
                FPCRoutePart wFPCRoutePart =
                        wOrderRoutePartList.stream().filter(p -> p.Name.equals("成品装箱工艺")).findFirst().get();
                wAPSTaskPart = new APSTaskPart(wFPCRoutePart, wIDOrderMap.get(wOrderID));
                Map<String, Float> wPlanDayNumMap = new HashMap<>();
                //新计划
                List<APSMonthImpPo> wList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wIDOrderMap.get(wOrderID).Code)).collect(Collectors.toList());
                for (APSMonthImpPo wAPSMonthImpPo : wList) {
                    if (wAPSMonthImpPo.FQTY_8 <= 0) {
                        continue;
                    }
                    wPlanDayNumMap.put(wSDF1.format(wAPSMonthImpPo.StartDate.getTime()), wAPSMonthImpPo.FQTY_8);
                }
                wAPSTaskPart.PlanDayNum = wPlanDayNumMap;
                wAPSTaskPart.ShiftPeriod = APSShiftPeriod.Month.getValue();
                wAPSTaskPart.PartStartTime =
                        wList.stream().min(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
                wAPSTaskPart.PartEndTime =
                        wList.stream().max(Comparator.comparing(APSMonthImpPo::getStartDate)).get().StartDate;
            }
        } catch (Exception ex) {
            logger.error("getApsTaskPart8", ex);
        }

        return wAPSTaskPart;
    }
    //endregion

    /**
     * 检查计划数量是否满足订单要求
     */
    private String CheckPlanNumber(List<APSTaskPart> wLessTaskList, List<APSMonthImpPo> wAPSMonthImpPoList,
                                   List<Integer> wOrderIDList, List<OMSOrder> wOMSOrderList, Map<Integer, Map<String,
            Integer>> wRouteIDRoutePartNameIDMap) {
        String wResult = "";
        try {
            Map<Integer, OMSOrder> wIDOrderMap =
                    wOMSOrderList.stream().collect(Collectors.toMap(OMSOrder::getID
                            , p -> p));

            //可超过计划的系统参数
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            double wDoubleValue = 1 +
                    StringUtils.parseDouble(BFCSystemConfigDAO.getInstance().BFC_GetValueByName(BMSEmployee.SysAdmin,
                            -1,
                            "Sys_Exceed_Proportion", wErrorCode));

            List<APSTaskPart> wAPSTaskPartList;
            for (int wOrderID : wOrderIDList) {
                OMSOrder wOMSOrder = wIDOrderMap.get(wOrderID);

                Map<String, Integer> wRouteNameMap = wRouteIDRoutePartNameIDMap.get(wOMSOrder.RouteID);

                List<APSMonthImpPo> wOrderMonthImpPoList =
                        wAPSMonthImpPoList.stream().filter(p -> p.OrderNo.equals(wOMSOrder.Code)).collect(Collectors.toList());
                //卷制工艺
                String wMsg = "";
                if (wRouteNameMap.containsKey(wOrderMonthImpPoList.get(0).RouteName_1)) {
                    wMsg = CheckFQTY1(wLessTaskList, wOrderID, wOMSOrder, wOrderMonthImpPoList, wDoubleValue);
                    if (StringUtils.isNotEmpty(wMsg)) {
                        wResult = wMsg;
                        return wResult;
                    }
                }
                //定型工艺
                if (wRouteNameMap.containsKey(wOrderMonthImpPoList.get(0).RouteName_2)) {
                    wMsg = CheckFQTY2(wLessTaskList, wOrderID, wOMSOrder, wOrderMonthImpPoList, wDoubleValue);
                    if (StringUtils.isNotEmpty(wMsg)) {
                        wResult = wMsg;
                        return wResult;
                    }
                }
                //喷金工艺
                if (wRouteNameMap.containsKey(wOrderMonthImpPoList.get(0).RouteName_3)) {
                    wMsg = CheckFQTY3(wLessTaskList, wOrderID, wOMSOrder, wOrderMonthImpPoList, wDoubleValue);
                    if (StringUtils.isNotEmpty(wMsg)) {
                        wResult = wMsg;
                        return wResult;
                    }
                }
                //赋能工艺
                if (wRouteNameMap.containsKey(wOrderMonthImpPoList.get(0).RouteName_4)) {
                    wMsg = CheckFQTY4(wLessTaskList, wOrderID, wOMSOrder, wOrderMonthImpPoList, wDoubleValue);
                    if (StringUtils.isNotEmpty(wMsg)) {
                        wResult = wMsg;
                        return wResult;
                    }
                }
                //芯子工艺
                if (wRouteNameMap.containsKey(wOrderMonthImpPoList.get(0).RouteName_5)) {
                    wMsg = CheckFQTY5(wLessTaskList, wOrderID, wOMSOrder, wOrderMonthImpPoList, wDoubleValue);
                    if (StringUtils.isNotEmpty(wMsg)) {
                        wResult = wMsg;
                        return wResult;
                    }
                }
                //真空注胶工艺
                if (wRouteNameMap.containsKey(wOrderMonthImpPoList.get(0).RouteName_6)) {
                    wMsg = CheckFQTY6(wLessTaskList, wOrderID, wOMSOrder, wOrderMonthImpPoList, wDoubleValue);
                    if (StringUtils.isNotEmpty(wMsg)) {
                        wResult = wMsg;
                        return wResult;
                    }
                }
                //试验工艺
                if (wRouteNameMap.containsKey(wOrderMonthImpPoList.get(0).RouteName_7)) {
                    wMsg = CheckFQTY7(wLessTaskList, wOrderID, wOMSOrder, wOrderMonthImpPoList, wDoubleValue);
                    if (StringUtils.isNotEmpty(wMsg)) {
                        wResult = wMsg;
                        return wResult;
                    }
                }
                //成品装箱工艺
                if (wRouteNameMap.containsKey(wOrderMonthImpPoList.get(0).RouteName_8)) {
                    wMsg = CheckFQTY8(wLessTaskList, wOrderID, wOMSOrder, wOrderMonthImpPoList, wDoubleValue);
                    if (StringUtils.isNotEmpty(wMsg)) {
                        wResult = wMsg;
                        return wResult;
                    }
                }
            }
        } catch (Exception ex) {
            logger.error("CheckPlanNumber", ex);
        }
        return wResult;
    }

    //region 检查各工艺数量
    private String CheckFQTY1(List<APSTaskPart> wLessTaskList, int wOrderID, OMSOrder wOMSOrder,
                              List<APSMonthImpPo> wOrderMonthImpPoList, double wDoubleValue) {
        List<APSTaskPart> wAPSTaskPartList;
        String wMsg = "";
        try {
            SimpleDateFormat wSDF = new SimpleDateFormat("yyyyMMdd");
            int wToday = StringUtils.parseInt(wSDF.format(Calendar.getInstance().getTime()));

            double wNewFQTY1 = wOrderMonthImpPoList.stream().mapToDouble(p -> p.FQTY_1).sum();
            double wOldFQTY1 = 0.0;
            if (wLessTaskList.stream().anyMatch(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_1))) {
                wAPSTaskPartList =
                        wLessTaskList.stream().filter(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_1)).collect(Collectors.toList());

                for (String wDateStr : wAPSTaskPartList.get(0).PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wOldFQTY1 += wAPSTaskPartList.get(0).PlanDayNum.get(wDateStr);
                    }
                }
            }

            float wOrderParmFQTY = (float) (wOMSOrder.FQTYPlan * wDoubleValue);

            if (wNewFQTY1 + wOldFQTY1 > wOrderParmFQTY) {
                wMsg = StringUtils.Format("导入失败：订单【{4}】计划数*系统参数：【{0}】，卷制工艺计划总数：【{1}】，其中已制定计划数为：【{2}】，新制定计划数为：【{3}】",
                        wOrderParmFQTY, wNewFQTY1 + wOldFQTY1, wOldFQTY1, wNewFQTY1, wOMSOrder.Code);
            }
        } catch (Exception ex) {
            logger.error("CheckFQTY1", ex);
        }
        return wMsg;
    }

    private String CheckFQTY2(List<APSTaskPart> wLessTaskList, int wOrderID, OMSOrder wOMSOrder,
                              List<APSMonthImpPo> wOrderMonthImpPoList, double wDoubleValue) {
        List<APSTaskPart> wAPSTaskPartList;
        String wMsg = "";
        try {
            SimpleDateFormat wSDF = new SimpleDateFormat("yyyyMMdd");
            int wToday = StringUtils.parseInt(wSDF.format(Calendar.getInstance().getTime()));

            double wNewFQTY1 = wOrderMonthImpPoList.stream().mapToDouble(p -> p.FQTY_2).sum();
            double wOldFQTY1 = 0.0;
            if (wLessTaskList.stream().anyMatch(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_2))) {
                wAPSTaskPartList =
                        wLessTaskList.stream().filter(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_2)).collect(Collectors.toList());

                for (String wDateStr : wAPSTaskPartList.get(0).PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wOldFQTY1 += wAPSTaskPartList.get(0).PlanDayNum.get(wDateStr);
                    }
                }
            }

            float wOrderParmFQTY = (float) (wOMSOrder.FQTYPlan * wDoubleValue);

            if (wNewFQTY1 + wOldFQTY1 > wOrderParmFQTY) {
                wMsg = StringUtils.Format("导入失败：订单【{4}】计划数*系统参数：【{0}】，定型工艺计划总数：【{1}】，其中已制定计划数为：【{2}】，新制定计划数为：【{3}】",
                        wOrderParmFQTY, wNewFQTY1 + wOldFQTY1, wOldFQTY1, wNewFQTY1, wOMSOrder.Code);
            }
        } catch (Exception ex) {
            logger.error("CheckFQTY2", ex);
        }
        return wMsg;
    }

    private String CheckFQTY3(List<APSTaskPart> wLessTaskList, int wOrderID, OMSOrder wOMSOrder,
                              List<APSMonthImpPo> wOrderMonthImpPoList, double wDoubleValue) {
        List<APSTaskPart> wAPSTaskPartList;
        String wMsg = "";
        try {
            SimpleDateFormat wSDF = new SimpleDateFormat("yyyyMMdd");
            int wToday = StringUtils.parseInt(wSDF.format(Calendar.getInstance().getTime()));

            double wNewFQTY1 = wOrderMonthImpPoList.stream().mapToDouble(p -> p.FQTY_3).sum();
            double wOldFQTY1 = 0.0;
            if (wLessTaskList.stream().anyMatch(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_3))) {
                wAPSTaskPartList =
                        wLessTaskList.stream().filter(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_3)).collect(Collectors.toList());

                for (String wDateStr : wAPSTaskPartList.get(0).PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wOldFQTY1 += wAPSTaskPartList.get(0).PlanDayNum.get(wDateStr);
                    }
                }
            }

            float wOrderParmFQTY = (float) (wOMSOrder.FQTYPlan * wDoubleValue);

            if (wNewFQTY1 + wOldFQTY1 > wOrderParmFQTY) {
                wMsg = StringUtils.Format("导入失败：订单【{4}】计划数*系统参数：【{0}】，喷金工艺计划总数：【{1}】，其中已制定计划数为：【{2}】，新制定计划数为：【{3}】",
                        wOrderParmFQTY, wNewFQTY1 + wOldFQTY1, wOldFQTY1, wNewFQTY1, wOMSOrder.Code);
            }
        } catch (Exception ex) {
            logger.error("CheckFQTY3", ex);
        }
        return wMsg;
    }

    private String CheckFQTY4(List<APSTaskPart> wLessTaskList, int wOrderID, OMSOrder wOMSOrder,
                              List<APSMonthImpPo> wOrderMonthImpPoList, double wDoubleValue) {
        List<APSTaskPart> wAPSTaskPartList;
        String wMsg = "";
        try {
            SimpleDateFormat wSDF = new SimpleDateFormat("yyyyMMdd");
            int wToday = StringUtils.parseInt(wSDF.format(Calendar.getInstance().getTime()));

            double wNewFQTY1 = wOrderMonthImpPoList.stream().mapToDouble(p -> p.FQTY_4).sum();
            double wOldFQTY1 = 0.0;
            if (wLessTaskList.stream().anyMatch(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_4))) {
                wAPSTaskPartList =
                        wLessTaskList.stream().filter(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_4)).collect(Collectors.toList());

                for (String wDateStr : wAPSTaskPartList.get(0).PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wOldFQTY1 += wAPSTaskPartList.get(0).PlanDayNum.get(wDateStr);
                    }
                }
            }

            float wOrderParmFQTY = (float) (wOMSOrder.FQTYPlan * wDoubleValue);

            if (wNewFQTY1 + wOldFQTY1 > wOrderParmFQTY) {
                wMsg = StringUtils.Format("导入失败：订单【{4}】计划数*系统参数：【{0}】，赋能工艺计划总数：【{1}】，其中已制定计划数为：【{2}】，新制定计划数为：【{3}】",
                        wOrderParmFQTY, wNewFQTY1 + wOldFQTY1, wOldFQTY1, wNewFQTY1, wOMSOrder.Code);
            }
        } catch (Exception ex) {
            logger.error("CheckFQTY4", ex);
        }
        return wMsg;
    }

    private String CheckFQTY5(List<APSTaskPart> wLessTaskList, int wOrderID, OMSOrder wOMSOrder,
                              List<APSMonthImpPo> wOrderMonthImpPoList, double wDoubleValue) {
        List<APSTaskPart> wAPSTaskPartList;
        String wMsg = "";
        try {
            SimpleDateFormat wSDF = new SimpleDateFormat("yyyyMMdd");
            int wToday = StringUtils.parseInt(wSDF.format(Calendar.getInstance().getTime()));

            double wNewFQTY1 = wOrderMonthImpPoList.stream().mapToDouble(p -> p.FQTY_5).sum();
            double wOldFQTY1 = 0.0;
            if (wLessTaskList.stream().anyMatch(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_5))) {
                wAPSTaskPartList =
                        wLessTaskList.stream().filter(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_5)).collect(Collectors.toList());

                for (String wDateStr : wAPSTaskPartList.get(0).PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wOldFQTY1 += wAPSTaskPartList.get(0).PlanDayNum.get(wDateStr);
                    }
                }
            }

            float wOrderParmFQTY = (float) (wOMSOrder.FQTYPlan * wDoubleValue);

            if (wNewFQTY1 + wOldFQTY1 > wOrderParmFQTY) {
                wMsg = StringUtils.Format("导入失败：订单【{4}】计划数*系统参数：【{0}】，芯子工艺计划总数：【{1}】，其中已制定计划数为：【{2}】，新制定计划数为：【{3}】",
                        wOrderParmFQTY, wNewFQTY1 + wOldFQTY1, wOldFQTY1, wNewFQTY1, wOMSOrder.Code);
            }
        } catch (Exception ex) {
            logger.error("CheckFQTY5", ex);
        }
        return wMsg;
    }

    private String CheckFQTY6(List<APSTaskPart> wLessTaskList, int wOrderID, OMSOrder wOMSOrder,
                              List<APSMonthImpPo> wOrderMonthImpPoList, double wDoubleValue) {
        List<APSTaskPart> wAPSTaskPartList;
        String wMsg = "";
        try {
            SimpleDateFormat wSDF = new SimpleDateFormat("yyyyMMdd");
            int wToday = StringUtils.parseInt(wSDF.format(Calendar.getInstance().getTime()));

            double wNewFQTY1 = wOrderMonthImpPoList.stream().mapToDouble(p -> p.FQTY_6).sum();
            double wOldFQTY1 = 0.0;
            if (wLessTaskList.stream().anyMatch(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_6))) {
                wAPSTaskPartList =
                        wLessTaskList.stream().filter(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_6)).collect(Collectors.toList());

                for (String wDateStr : wAPSTaskPartList.get(0).PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wOldFQTY1 += wAPSTaskPartList.get(0).PlanDayNum.get(wDateStr);
                    }
                }
            }

            float wOrderParmFQTY = (float) (wOMSOrder.FQTYPlan * wDoubleValue);

            if (wNewFQTY1 + wOldFQTY1 > wOrderParmFQTY) {
                wMsg = StringUtils.Format("导入失败：订单【{4}】计划数*系统参数：【{0}】，真空注胶工艺计划总数：【{1}】，其中已制定计划数为：【{2}】，新制定计划数为：【{3}】",
                        wOrderParmFQTY, wNewFQTY1 + wOldFQTY1, wOldFQTY1, wNewFQTY1, wOMSOrder.Code);
            }
        } catch (Exception ex) {
            logger.error("CheckFQTY6", ex);
        }
        return wMsg;
    }

    private String CheckFQTY7(List<APSTaskPart> wLessTaskList, int wOrderID, OMSOrder wOMSOrder,
                              List<APSMonthImpPo> wOrderMonthImpPoList, double wDoubleValue) {
        List<APSTaskPart> wAPSTaskPartList;
        String wMsg = "";
        try {
            SimpleDateFormat wSDF = new SimpleDateFormat("yyyyMMdd");
            int wToday = StringUtils.parseInt(wSDF.format(Calendar.getInstance().getTime()));

            double wNewFQTY1 = wOrderMonthImpPoList.stream().mapToDouble(p -> p.FQTY_7).sum();
            double wOldFQTY1 = 0.0;
            if (wLessTaskList.stream().anyMatch(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_7))) {
                wAPSTaskPartList =
                        wLessTaskList.stream().filter(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_7)).collect(Collectors.toList());

                for (String wDateStr : wAPSTaskPartList.get(0).PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wOldFQTY1 += wAPSTaskPartList.get(0).PlanDayNum.get(wDateStr);
                    }
                }
            }

            float wOrderParmFQTY = (float) (wOMSOrder.FQTYPlan * wDoubleValue);

            if (wNewFQTY1 + wOldFQTY1 > wOrderParmFQTY) {
                wMsg = StringUtils.Format("导入失败：订单【{4}】计划数*系统参数：【{0}】，试验工艺计划总数：【{1}】，其中已制定计划数为：【{2}】，新制定计划数为：【{3}】",
                        wOrderParmFQTY, wNewFQTY1 + wOldFQTY1, wOldFQTY1, wNewFQTY1, wOMSOrder.Code);
            }
        } catch (Exception ex) {
            logger.error("CheckFQTY7", ex);
        }
        return wMsg;
    }

    private String CheckFQTY8(List<APSTaskPart> wLessTaskList, int wOrderID, OMSOrder wOMSOrder,
                              List<APSMonthImpPo> wOrderMonthImpPoList, double wDoubleValue) {
        List<APSTaskPart> wAPSTaskPartList;
        String wMsg = "";
        try {
            SimpleDateFormat wSDF = new SimpleDateFormat("yyyyMMdd");
            int wToday = StringUtils.parseInt(wSDF.format(Calendar.getInstance().getTime()));

            double wNewFQTY1 = wOrderMonthImpPoList.stream().mapToDouble(p -> p.FQTY_8).sum();
            double wOldFQTY1 = 0.0;
            if (wLessTaskList.stream().anyMatch(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_8))) {
                wAPSTaskPartList =
                        wLessTaskList.stream().filter(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wOrderMonthImpPoList.get(0).RouteName_8)).collect(Collectors.toList());

                for (String wDateStr : wAPSTaskPartList.get(0).PlanDayNum.keySet()) {
                    //判断当前日期是否小于
                    int wDate = StringUtils.parseInt(wDateStr.replaceAll("-", ""));
                    if (wDate < wToday) {
                        wOldFQTY1 += wAPSTaskPartList.get(0).PlanDayNum.get(wDateStr);
                    }
                }
            }

            float wOrderParmFQTY = (float) (wOMSOrder.FQTYPlan * wDoubleValue);

            if (wNewFQTY1 + wOldFQTY1 > wOrderParmFQTY) {
                wMsg = StringUtils.Format("导入失败：订单【{4}】计划数*系统参数：【{0}】，成品装箱工艺计划总数：【{1}】，其中已制定计划数为：【{2}】，新制定计划数为：【{3}】",
                        wOrderParmFQTY, wNewFQTY1 + wOldFQTY1, wOldFQTY1, wNewFQTY1, wOMSOrder.Code);
            }
        } catch (Exception ex) {
            logger.error("CheckFQTY8", ex);
        }
        return wMsg;
    }
    //endregion

    /**
     * 自动补齐数量
     */
    private void AutoCaclPlanNumber(APSMonthImpPo wAPSMonthImpPo, ExcelLineData wExcelLineData) {
        try {
            for (int i = 2; i < wExcelLineData.colData.size(); i++) {
                //定型
                if (wAPSMonthImpPo.FQTY_2 <= 0 && StringUtils.isNotEmpty(wExcelLineData.colData.get(i)) && i <= 2) {
                    wAPSMonthImpPo.FQTY_2 = StringUtils.parseFloat(wExcelLineData.colData.get(i));
                }
                //喷金
                if (wAPSMonthImpPo.FQTY_3 <= 0 && StringUtils.isNotEmpty(wExcelLineData.colData.get(i)) && i <= 3) {
                    wAPSMonthImpPo.FQTY_3 = StringUtils.parseFloat(wExcelLineData.colData.get(i));
                }
                //赋能
                if (wAPSMonthImpPo.FQTY_4 <= 0 && StringUtils.isNotEmpty(wExcelLineData.colData.get(i)) && i <= 4) {
                    wAPSMonthImpPo.FQTY_4 = StringUtils.parseFloat(wExcelLineData.colData.get(i));
                }
                //芯子
                if (wAPSMonthImpPo.FQTY_5 <= 0 && StringUtils.isNotEmpty(wExcelLineData.colData.get(i)) && i <= 5) {
                    wAPSMonthImpPo.FQTY_5 = StringUtils.parseFloat(wExcelLineData.colData.get(i));
                }
                //真空注胶
                if (wAPSMonthImpPo.FQTY_6 <= 0 && StringUtils.isNotEmpty(wExcelLineData.colData.get(i)) && i <= 6) {
                    wAPSMonthImpPo.FQTY_6 = StringUtils.parseFloat(wExcelLineData.colData.get(i));
                }
                //试验
                if (wAPSMonthImpPo.FQTY_7 <= 0 && StringUtils.isNotEmpty(wExcelLineData.colData.get(i)) && i <= 7) {
                    wAPSMonthImpPo.FQTY_7 = StringUtils.parseFloat(wExcelLineData.colData.get(i));
                }
                //成品装箱
//                if (wAPSMonthImpPo.FQTY_8 <= 0 && StringUtils.isNotEmpty(wExcelLineData.colData.get(i)) && i <= 8) {
//                    wAPSMonthImpPo.FQTY_8 = StringUtils.parseFloat(wExcelLineData.colData.get(i));
//                }
            }
        } catch (Exception ex) {
            logger.error("AutoCaclPlanNumber", ex);
        }
    }

    @Override
    public ServiceResult<Integer> APS_QueryGanttData(BMSEmployee wLoginUser, List<APSTaskPart> wAPSTaskPartList) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            // 排序
            wAPSTaskPartList.sort(Comparator.comparing(APSTaskPart::getRoutePartOrder));

            List<APSTaskPartPoint> wAPSTaskPartPointList = new ArrayList<>();
            if (wAPSTaskPartList.get(0).ShiftPeriod == APSShiftPeriod.Week.getValue()) {
                List<Integer> wTaskPartIDList =
                        wAPSTaskPartList.stream().map(p -> p.ID).distinct().collect(Collectors.toList());
                List<Integer> wAPSTaskPartPointIDList =
                        APSTaskPartPointDAO.getInstance().APS_QueryTaskPartPointIDListByTaskPartIDList(wLoginUser,
                                wTaskPartIDList, wErrorCode);
                if (wAPSTaskPartPointIDList.size() > 0) {
                    Map<String, Object> wParams = new HashMap<String, Object>();
                    wAPSTaskPartPointList = mAPSTaskPartPointService.SelectPOList(wLoginUser, wAPSTaskPartPointIDList
                            , wParams, Pagination.getNewMaxSize(), wErrorCode);
                }
                for (APSTaskPart wAPSTaskPart : wAPSTaskPartList) {
                    wAPSTaskPart.TaskPartPointList =
                            wAPSTaskPartPointList.stream().filter(p -> p.TaskPartID == wAPSTaskPart.ID).collect(Collectors.toList());
                }
            }

            //获取订单
            Map<String, Object> wParams = new HashMap<String, Object>();
            List<Integer> wOrderIDList =
                    wAPSTaskPartList.stream().map(p -> p.OrderID).distinct().collect(Collectors.toList());
            List<OMSOrder> wOrderList = mOMSOrderService.SelectPOList(wLoginUser, wOrderIDList, wParams,
                    Pagination.getNewMaxSize(), wErrorCode);
            if (wOrderList == null || wOrderList.size() <= 0) {
                wResult.FaultCode += ExceptionTypes.DBSQL.getLabel();
                return wResult;
            }

            //获取甘特图数据
            List<APSGanttLink> wAPSGanttLinkList = new ArrayList<>();
            List<FPCRoutePart> wFPCRoutePartList = new ArrayList<>();
            List<FPCRoutePartPoint> wFPCRoutePartPointList = new ArrayList<>();
            Map<String, Object> wParams1 = new HashMap<String, Object>();
            wFPCRoutePartList = mFPCRoutePartService.SelectPOList(wLoginUser,
                    wAPSTaskPartList.stream().map(p -> p.RoutePartID).distinct().collect(Collectors.toList()),
                    wParams1, Pagination.getMaxSize(), wErrorCode);
            List<Integer> wRoutePartPointIDList = new ArrayList<>();
            for (APSTaskPart wAPSTaskPart : wAPSTaskPartList) {
                for (APSTaskPartPoint wAPSTaskPartPoint : wAPSTaskPart.TaskPartPointList) {
                    if (wRoutePartPointIDList.stream().noneMatch(p -> p == wAPSTaskPartPoint.RoutePartPointID)) {
                        wRoutePartPointIDList.add(wAPSTaskPartPoint.RoutePartPointID);
                    }
                }
            }
            if (wRoutePartPointIDList.size() > 0) {
                wFPCRoutePartPointList = mFPCRoutePartPointService.SelectPOList(wLoginUser,
                        wRoutePartPointIDList,
                        wParams1, Pagination.getMaxSize(), wErrorCode);
            }

            //获取甘特图数据+连线数据
            List<APSGanttData> wAPSGanttDataList = APSTaskPartDAO.getInstance().APS_GetAPSGanttDataList(wLoginUser,
                    wAPSTaskPartList, wOrderList, wAPSGanttLinkList, wFPCRoutePartList, wFPCRoutePartPointList,
                    wErrorCode);
            wResult.CustomResult.put("APSGanttData", wAPSGanttDataList);
            wResult.CustomResult.put("APSGanttLink", wAPSGanttLinkList);

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> APS_WeeklyPlanImport(BMSEmployee wLoginUser, ExcelData wExcelData) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelData == null || wExcelData.sheetData == null || wExcelData.sheetData.size() <= 0) {
                wResult.FaultCode += "导入失败：Excel格式错误!!!";
                return wResult;
            }

            ExcelSheetData wExcelSheetData = wExcelData.sheetData.get(0);
            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                wResult.FaultCode += "导入失败：Excel无内容!!!";
                return wResult;
            }

            //①订单数据
            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("Status", "2,3,4");
            List<OMSOrder> wOMSOrderList = mOMSOrderService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wOMSOrderList == null || wOMSOrderList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到可导入的订单信息!!!";
                return wResult;
            }
            Map<String, Integer> wCodeRouteIDOrderMap =
                    wOMSOrderList.stream().collect(Collectors.toMap(OMSOrder::getCode
                            , OMSOrder::getRouteID));
            Map<String, Integer> wCodeIDOrderMap =
                    wOMSOrderList.stream().collect(Collectors.toMap(OMSOrder::getCode
                            , OMSOrder::getID));

            //②订单工艺数据
            List<Integer> wRouteIDList =
                    wOMSOrderList.stream().map(p -> p.RouteID).distinct().collect(Collectors.toList());
            wParams.clear();
            wParams.put("RouteID", StringUtils.Join(",", wRouteIDList));
            wParams.put("Active", 1);
            List<FPCRoutePartPoint> wFPCRoutePartPointList = mFPCRoutePartPointService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wFPCRoutePartPointList == null || wFPCRoutePartPointList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到订单工艺信息!!!";
                return wResult;
            }

            Map<Integer, List<FPCRoutePartPoint>> wRouteIDRoutePartPointMap = new HashMap<>();
            List<FPCRoutePartPoint> wTempList;
            for (int wRouteID : wRouteIDList) {
                wTempList =
                        wFPCRoutePartPointList.stream().filter(p -> p.RouteID == wRouteID).collect(Collectors.toList());
                wTempList.sort(Comparator.comparing(FPCRoutePartPoint::getRoutePartOrder)
                        .thenComparing(FPCRoutePartPoint::getOrderID));
                wRouteIDRoutePartPointMap.put(wRouteID, wTempList);
            }

            Calendar wBaseTime = Calendar.getInstance();
            wBaseTime.set(2010, 0, 1, 0, 0, 0);

            SimpleDateFormat wSDF = new SimpleDateFormat("yyyy-MM-dd");

            Calendar wTodayTime = Calendar.getInstance();
            wTodayTime.set(Calendar.HOUR_OF_DAY, 0);
            wTodayTime.set(Calendar.MINUTE, 0);
            wTodayTime.set(Calendar.SECOND, 0);
            wTodayTime.add(Calendar.SECOND, -1);

            String wCurrentTime = wSDF.format(Calendar.getInstance().getTime());

//            List<APSWeekthImpPo> wAPSWeekthImpPoList = this.APS_InitWeekthImpPoList(wLoginUser, wErrorCode);
            List<APSWeekthImpPo> wAPSWeekthImpPoList = this.APS_InitWeekthImpPoList_V1(wLoginUser, wExcelSheetData,
                    wErrorCode);

            List<Integer> wOrderIDList = new ArrayList<>();
            List<APSTaskPartPoint> wAPSTaskPartPointList = new ArrayList<>();
            for (int i = 2; i < wExcelSheetData.lineData.size(); i++) {
                ExcelLineData wExcelLineData = wExcelSheetData.lineData.get(i);
                int wIndex = 0;

//                if (wExcelLineData.colData.size() < 24) {
//                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，数据不足24列，请检查填写数据!!!", i + 1);
//                    return wResult;
//                }

                //计划日期
                String wCol1 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol1)) {
                    continue;
                }
                Calendar wStartDate = StringUtils.parseCalendar(wCol1);
                if (wStartDate.compareTo(wBaseTime) <= 0) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，开始日期输入值【{1}】不合法!!!", i + 1, wCol1);
                    return wResult;
                }
                if (wStartDate.compareTo(wTodayTime) < 0) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，开始日期【{1}】小于当前日期!!!", i + 1,
                            wSDF.format(wStartDate.getTime()));
                    return wResult;
                }
                //订单号
                String wCol2 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wCodeRouteIDOrderMap.containsKey(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号【{1}】不存在或订单状态不满足导入要求!!!", i + 1,
                            wCol2);
                    return wResult;
                }
                int wRouteID = wCodeRouteIDOrderMap.get(wCol2);
                if (!wRouteIDRoutePartPointMap.containsKey(wRouteID)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，订单号【{1}】工艺路线不存在!!!", i + 1,
                            wCol2);
                    return wResult;
                }

                wOrderIDList.add(wCodeIDOrderMap.get(wCol2));

                //根据RouteID查询工艺数据
                List<FPCRoutePartPoint> wFPCRoutePartPointList_Order = wRouteIDRoutePartPointMap.get(wRouteID);

                for (int j = 2; j < wExcelLineData.colData.size(); j++) {
                    Float wValue = StringUtils.parseFloat(wExcelLineData.colData.get(j));
                    if (wValue <= 0) {
                        continue;
                    }

                    int wTempIndex = j;
                    APSWeekthImpPo wAPSWeekthImpPo =
                            wAPSWeekthImpPoList.stream().filter(p -> p.ColNum == wTempIndex).findFirst().get();
                    if (wFPCRoutePartPointList_Order.stream().noneMatch(p -> p.RoutePartName.equals(wAPSWeekthImpPo.RoutePartName)
                            && p.Name.equals(wAPSWeekthImpPo.RoutePartPointName))) {
                        continue;
                    }
                    FPCRoutePartPoint wFPCRoutePartPoint =
                            wFPCRoutePartPointList_Order.stream().filter(p -> p.RoutePartName.equals(wAPSWeekthImpPo.RoutePartName)
                                    && p.Name.equals(wAPSWeekthImpPo.RoutePartPointName)).findFirst().get();
                    if (wAPSTaskPartPointList.stream().anyMatch(p -> p.RoutePartName.equals(wAPSWeekthImpPo.RoutePartName) && p.RoutePartPointName.equals(wAPSWeekthImpPo.RoutePartPointName) && p.OrderNo.equals(wCol2))) {
                        APSTaskPartPoint wAPSTaskPartPoint =
                                wAPSTaskPartPointList.stream().filter(p -> p.RoutePartName.equals(wAPSWeekthImpPo.RoutePartName) && p.RoutePartPointName.equals(wAPSWeekthImpPo.RoutePartPointName) && p.OrderNo.equals(wCol2)).findFirst().get();
                        wAPSTaskPartPoint.PlanDayNum.put(wSDF.format(wStartDate.getTime()), wValue);
                    } else {
                        APSTaskPartPoint wAPSTaskPartPoint = new APSTaskPartPoint();
                        wAPSTaskPartPoint.OrderID = wCodeIDOrderMap.get(wCol2);
                        wAPSTaskPartPoint.OrderNo = wCol2;
                        wAPSTaskPartPoint.RoutePartID = wFPCRoutePartPoint.RoutePartID;
                        wAPSTaskPartPoint.RoutePartName = wFPCRoutePartPoint.RoutePartName;
                        wAPSTaskPartPoint.RoutePartPointID = wFPCRoutePartPoint.ID;
                        wAPSTaskPartPoint.RoutePartPointName = wFPCRoutePartPoint.Name;
                        wAPSTaskPartPoint.PlanDayNum = new HashMap<>();
                        wAPSTaskPartPoint.PlanDayNum.put(wSDF.format(wStartDate.getTime()), wValue);
                        wAPSTaskPartPointList.add(wAPSTaskPartPoint);
                    }
                }
            }

            if (wAPSTaskPartPointList.size() <= 0) {
                wResult.FaultCode += StringUtils.Format("导入失败：订单工艺中没有相同的工序或工序的计划数量均未填写!!!");
                return wResult;
            }

            wOrderIDList = wOrderIDList.stream().distinct().collect(Collectors.toList());

            //每个工序检查计划是否满足要求，若不满足，则报错（工序计划增加历史完成数（通过SQL sum更新，报工触发）；保证历史完成数+当日已开工计划数+导入计划数<=订单数*系统参数比例，同时>=订单计划数）
            String wMsg = APS_CheckPlanNumber_Week(wLoginUser, wRouteIDRoutePartPointMap, wOrderIDList, wOMSOrderList
                    , wAPSTaskPartPointList, wErrorCode);
            if (StringUtils.isNotEmpty(wMsg)) {
                wResult.FaultCode += wMsg;
                return wResult;
            }

            //创建新计划
            List<APSTaskPart> wNewTaskList = APS_CreateNewWeekTask(wAPSTaskPartPointList, wOrderIDList, wOMSOrderList,
                    wRouteIDRoutePartPointMap);
            //调用保存接口，保存新计划
            if (wNewTaskList != null && wNewTaskList.size() > 0) {
                wResult = ASVServiceImpl.getInstance().APS_SaveSchedulingVersion(wLoginUser, wNewTaskList,
                        APSShiftPeriod.Week.getValue());
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("APS_WeeklyPlanImport", e);
        }
        return wResult;
    }

    /**
     * 初始化周计划导入表头模板
     */
    private List<APSWeekthImpPo> APS_InitWeekthImpPoList_V1(BMSEmployee wLoginUser, ExcelSheetData wExcelSheetData,
                                                            OutResult<Integer> wErrorCode) {
        List<APSWeekthImpPo> wResult = new ArrayList<>();
        try {
            if (wExcelSheetData.lineData.size() < 2) {
                return wResult;
            }
            //①获取工艺列Map
            List<String> wList = new ArrayList<>();
            for (int i = 2; i < wExcelSheetData.lineData.get(0).colData.size(); i++) {
                wList.add(wExcelSheetData.lineData.get(0).colData.get(i));
            }
            List<String> wNotEmptyList = ExcelUtil.fillEmptyStrings(wList);
            Map<Integer, String> wColMap = new HashMap<>();
            int wIndex = 2;
            for (String wStr : wNotEmptyList) {
                wColMap.put(wIndex++, wStr);
            }
            //②遍历第二行表头，添加结果集
            List<String> wLineColList = wExcelSheetData.lineData.get(1).colData;
            APSWeekthImpPo wAPSWeekthImpPo;
            String routePartName = "";
            for (int i = 2; i < wLineColList.size(); i++) {
                //获取工艺名称
                if (wColMap.containsKey(i)) {
                    routePartName = wColMap.get(i);
                }
                wAPSWeekthImpPo = new APSWeekthImpPo(routePartName, wLineColList.get(i), i);
                wResult.add(wAPSWeekthImpPo);
            }
        } catch (Exception ex) {
            logger.error("APS_InitWeekthImpPoList_V1", ex);
        }
        return wResult;
    }

    /**
     * 创建周计划
     */
    private List<APSTaskPart> APS_CreateNewWeekTask(List<APSTaskPartPoint> wAPSTaskPartPointList,
                                                    List<Integer> wOrderIDList,
                                                    List<OMSOrder> wOMSOrderList, Map<Integer,
            List<FPCRoutePartPoint>> wRouteIDRoutePartPointMap) {
        List<APSTaskPart> wResult = new ArrayList<APSTaskPart>();
        try {
            Map<Integer, OMSOrder> wIDOrderMap =
                    wOMSOrderList.stream().collect(Collectors.toMap(OMSOrder::getID
                            , p -> p));

            List<String> wRoutePartNameList =
                    wAPSTaskPartPointList.stream().map(p -> p.RoutePartName).distinct().collect(Collectors.toList());
            for (int wOrderID : wOrderIDList) {
                for (String wRoutePartName : wRoutePartNameList) {
                    //查询工艺数据
                    List<FPCRoutePartPoint> wFPCRoutePartPointList =
                            wRouteIDRoutePartPointMap.get(wIDOrderMap.get(wOrderID).RouteID);
                    if (wFPCRoutePartPointList == null || wFPCRoutePartPointList.size() <= 0) {
                        continue;
                    }
                    wFPCRoutePartPointList =
                            wFPCRoutePartPointList.stream().filter(p -> p.RoutePartName.equals(wRoutePartName)).collect(Collectors.toList());
                    //①查询工序任务列表
                    List<APSTaskPartPoint> wTempTaksList =
                            wAPSTaskPartPointList.stream().filter(p -> p.OrderID == wOrderID && p.RoutePartName.equals(wRoutePartName)).collect(Collectors.toList());
                    if (wTempTaksList.size() <= 0) {
                        continue;
                    }

                    //④计算工序计划开始时间和结束时间
                    List<Calendar> wDateList = new ArrayList<>();
                    for (APSTaskPartPoint wAPSTaskPartPoint : wTempTaksList) {

                        FPCRoutePartPoint wFPCRoutePartPoint =
                                wFPCRoutePartPointList.stream().filter(p -> p.Name.equals(wAPSTaskPartPoint.RoutePartPointName)).findFirst().get();

                        List<Calendar> wD1List = new ArrayList<>();
                        for (String wDateStr : wAPSTaskPartPoint.PlanDayNum.keySet()) {
                            wD1List.add(StringUtils.parseCalendar(wDateStr));
                        }
                        wAPSTaskPartPoint.PartPointStartTime = wD1List.stream().min(Comparator.comparing(p -> p)).get();
                        wAPSTaskPartPoint.PartPointEndTime = wD1List.stream().max(Comparator.comparing(p -> p)).get();
                        //其他属性赋值
                        wAPSTaskPartPoint.LineID = wIDOrderMap.get(wOrderID).LineID;
                        wAPSTaskPartPoint.ProductID = wIDOrderMap.get(wOrderID).ProductID;
                        wAPSTaskPartPoint.StationID = wFPCRoutePartPoint.StationID;
                        wAPSTaskPartPoint.ShiftPeriod = APSShiftPeriod.Week.getValue();
                        wAPSTaskPartPoint.Status = APSTaskStatus.Saved.getValue();
                        wAPSTaskPartPoint.PlanNum = wIDOrderMap.get(wOrderID).FQTYPlan;

                        wDateList.addAll(wD1List);
                    }

                    //②创建周计划
                    APSTaskPart wAPSTaskPart = new APSTaskPart();
                    wAPSTaskPart.LineID = wIDOrderMap.get(wOrderID).LineID;
                    wAPSTaskPart.OrderID = wIDOrderMap.get(wOrderID).ID;
                    wAPSTaskPart.ProductID = wIDOrderMap.get(wOrderID).ProductID;
                    wAPSTaskPart.RoutePartID = wTempTaksList.get(0).RoutePartID;
                    wAPSTaskPart.WorkShopID = wFPCRoutePartPointList.get(0).WorkShopID;
                    wAPSTaskPart.WorkAreaID = wFPCRoutePartPointList.get(0).WorkAreaID;
                    wAPSTaskPart.PartType = 0;
                    wAPSTaskPart.RouteType = FPCRouteType.RoutePartWorkArea.getValue();
                    wAPSTaskPart.PlantNum = wIDOrderMap.get(wOrderID).FQTYPlan;
                    wAPSTaskPart.Active = 1;
                    wAPSTaskPart.ShiftPeriod = APSShiftPeriod.Week.getValue();
                    //③计算周计划开始时间和结束时间
                    wAPSTaskPart.PartStartTime = wDateList.stream().min(Comparator.comparing(p -> p)).get();
                    wAPSTaskPart.PartEndTime = wDateList.stream().max(Comparator.comparing(p -> p)).get();
                    //⑤赋值工序计划
                    wAPSTaskPart.TaskPartPointList = wTempTaksList;
                    wResult.add(wAPSTaskPart);
                }
            }
        } catch (Exception e) {
            logger.error("APS_CreateNewWeekTask", e);
        }
        return wResult;
    }

    //region 验证工序计划数是否满足条件
    private String APS_CheckPlanNumber_Week(BMSEmployee wLoginUser,
                                            Map<Integer, List<FPCRoutePartPoint>> wRouteIDRoutePartPointMap,
                                            List<Integer> wOrderIDList,
                                            List<OMSOrder> wOMSOrderList,
                                            List<APSTaskPartPoint> wAPSTaskPartPointList,
                                            OutResult<Integer> wErrorCode) {
        String wResult = "";
        try {
            //①根据订单查询历史工序计划数据
            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("OrderID", StringUtils.Join(",", wOrderIDList));
            wParams.put("Active", 1);
            wParams.put("IsCurrent", 1);
            List<APSTaskPartPoint> wHisTaskList = mAPSTaskPartPointService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            //②根据订单查询当日已开工日计划数据
            Calendar wSTime = Calendar.getInstance();
            wSTime.set(wSTime.get(Calendar.YEAR), wSTime.get(Calendar.MONTH), wSTime.get(Calendar.DATE), 0, 0, 0);
            wSTime.add(Calendar.SECOND, -1);

            Calendar wETime = Calendar.getInstance();
            wETime.set(wETime.get(Calendar.YEAR), wETime.get(Calendar.MONTH), wETime.get(Calendar.DATE), 23, 59, 59);
            wParams.clear();
            wParams.put("OrderID", StringUtils.Join(",", wOrderIDList));
            wParams.put("Status", APSTaskStatus.Started.getValue());
            wParams.put("StationDateStartTime", wSTime);
            wParams.put("StationDateEndTime", wETime);
            List<APSTaskPartPointDay> wTodayTaskList = mAPSTaskPartPointDayService.SelectPOList(wLoginUser,
                    wParams, Pagination.getNewMaxSize(),
                    wErrorCode);
            //③查询系统参数
            double wDoubleValue = 1 +
                    StringUtils.parseDouble(BFCSystemConfigDAO.getInstance().BFC_GetValueByName(wLoginUser, -1,
                            "Sys_Exceed_Proportion", wErrorCode));
            //④遍历判定，工序的数量是否满足要求，若不满足则报错
            Map<Integer, OMSOrder> wIDOrderMap =
                    wOMSOrderList.stream().collect(Collectors.toMap(OMSOrder::getID
                            , p -> p));
            for (int wOrderID : wOrderIDList) {
                OMSOrder wOMSOrder = wIDOrderMap.get(wOrderID);
                List<FPCRoutePartPoint> wFPCRoutePartPointList = wRouteIDRoutePartPointMap.get(wOMSOrder.RouteID);
                for (FPCRoutePartPoint wFPCRoutePartPoint : wFPCRoutePartPointList) {
                    //①历史完成数
                    float wHisFinishedFQTY = 0.0f;
                    if (wHisTaskList.stream().anyMatch(p -> p.OrderID == wOrderID
                            && p.RoutePartID == wFPCRoutePartPoint.RoutePartID && p.RoutePartPointID == wFPCRoutePartPoint.ID)) {
                        wHisFinishedFQTY = wHisTaskList.stream().filter(p -> p.OrderID == wOrderID
                                && p.RoutePartID == wFPCRoutePartPoint.RoutePartID && p.RoutePartPointID == wFPCRoutePartPoint.ID).findFirst().get().HisActNum;
                    }
                    //②当日已开工计划数
                    float wTodayPlanFQTY = 0.0f;
                    if (wTodayTaskList.stream().anyMatch(p -> p.OrderID == wOrderID
                            && p.RoutePartID == wFPCRoutePartPoint.RoutePartID && p.RoutePartPointID == wFPCRoutePartPoint.ID)) {
                        wTodayPlanFQTY = (float) wTodayTaskList.stream().filter(p -> p.OrderID == wOrderID
                                && p.RoutePartID == wFPCRoutePartPoint.RoutePartID && p.RoutePartPointID == wFPCRoutePartPoint.ID).mapToDouble(p -> p.PlantNum).sum();
                    }
                    //③导入计划数
                    float wImpotFQTY = 0.0f;
                    if (wAPSTaskPartPointList.stream().anyMatch(p -> p.OrderID == wOrderID && p.RoutePartID == wFPCRoutePartPoint.RoutePartID && p.RoutePartPointID == wFPCRoutePartPoint.ID)) {
                        APSTaskPartPoint wAPSTaskPartPoint =
                                wAPSTaskPartPointList.stream().filter(p -> p.OrderID == wOrderID && p.RoutePartID == wFPCRoutePartPoint.RoutePartID && p.RoutePartPointID == wFPCRoutePartPoint.ID).findFirst().get();
                        wImpotFQTY = (float) wAPSTaskPartPoint.PlanDayNum.values().stream().mapToDouble(p -> p).sum();
                    }
                    //④订单数*系统比例参数
                    float wOrderParmFQTY = (float) (wOMSOrder.FQTYPlan * wDoubleValue);
                    //判断（历史完成数+当日已开工计划数+导入计划数<=订单数*系统参数比例，同时>=订单计划数）
                    float wTotal = wHisFinishedFQTY + wTodayPlanFQTY + wImpotFQTY;
                    if (wTotal <= wOrderParmFQTY) {
                    } else {
                        wResult = StringUtils.Format("导入失败：【{4}】-【{5}】-【{6}】历史完成数[{0}]+当日已开工计划数[{1}]+导入计划数[{2" +
                                        "}]应<=订单数*系统参数比例[{3" +
                                        "}]!!!", wHisFinishedFQTY, wTodayPlanFQTY,
                                wImpotFQTY,
                                wOrderParmFQTY,
                                wOMSOrder.Code, wFPCRoutePartPoint.RoutePartName,
                                wFPCRoutePartPoint.Name);
                        return wResult;
                    }
                }
            }
        } catch (Exception e) {
            logger.error("APS_CheckPlanNumber_Week", e);
        }
        return wResult;
    }
    //endregion

    //region 初始化周计划导入表头模板
    private List<APSWeekthImpPo> APS_InitWeekthImpPoList(BMSEmployee wLoginUser, OutResult<Integer> wErrorCode) {
        List<APSWeekthImpPo> wResult = new ArrayList<APSWeekthImpPo>();
        try {
            int wIndex = 2;
            APSWeekthImpPo wAPSWeekthImpPo = new APSWeekthImpPo("卷制工艺", "卷制", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("卷制工艺", "喷码", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("卷制工艺", "包纸", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("卷制工艺", "压装", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("定型工艺", "真空热定型", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("定型工艺", "解压装", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("喷金工艺", "包纸", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("喷金工艺", "喷金", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("喷金工艺", "拆包", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("赋能工艺", "赋能", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("芯子工艺", "芯子锡焊", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("真空注胶工艺", "装模", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("真空注胶工艺", "预热", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("真空注胶工艺", "真空浇注", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("真空注胶工艺", "保压", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("真空注胶工艺", "预固化", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("真空注胶工艺", "拆模", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("真空注胶工艺", "修边打磨", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("真空注胶工艺", "后固化", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("试验工艺", "例行试验", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("成品装箱工艺", "粘贴标识", wIndex++);
            wResult.add(wAPSWeekthImpPo);

            wAPSWeekthImpPo = new APSWeekthImpPo("成品装箱工艺", "打包装箱", wIndex++);
            wResult.add(wAPSWeekthImpPo);
        } catch (Exception e) {
            logger.error("APS_InitWeekthImpPoList", e);
        }
        return wResult;
    }
    //endregion

    @Override
    public ServiceResult<List<APSMonthShowPo>> APS_QueryMonthDataChangeToShow(BMSEmployee wLoginUser,
                                                                              int wSchedulingVersionBPMID) {
        ServiceResult<List<APSMonthShowPo>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("ID", wSchedulingVersionBPMID);
            APSSchedulingVersionBPM wAPSSchedulingVersionBPM =
                    ASVServiceImpl.getInstance().APS_QuerySchedulingVersionBPMInfo(wLoginUser, wParams).Result;
            if (wAPSSchedulingVersionBPM == null || wAPSSchedulingVersionBPM.ID <= 0
                    || wAPSSchedulingVersionBPM.TaskPartList == null
                    || wAPSSchedulingVersionBPM.TaskPartList.size() <= 0) {
                wResult.FaultCode += ExceptionTypes.DBSQL.getValue();
                return wResult;
            }

            Map<String, Integer> wRoutePartNameIndexMap = new HashMap<>();
            wRoutePartNameIndexMap.put("卷制工艺", 0);
            wRoutePartNameIndexMap.put("定型工艺", 1);
            wRoutePartNameIndexMap.put("喷金工艺", 2);
            wRoutePartNameIndexMap.put("赋能工艺", 3);
            wRoutePartNameIndexMap.put("芯子工艺", 4);
            wRoutePartNameIndexMap.put("真空注胶工艺", 5);
            wRoutePartNameIndexMap.put("试验工艺", 6);
            wRoutePartNameIndexMap.put("成品装箱工艺", 7);

            //遍历赋值
            for (APSTaskPart wAPSTaskPart : wAPSSchedulingVersionBPM.TaskPartList) {
                for (String wDateStr : wAPSTaskPart.PlanDayNum.keySet()) {
                    //根据订单、日期查询数据
                    if (wResult.Result.stream().anyMatch(p -> p.OrderNo.equals(wAPSTaskPart.OrderNo) && p.Date.equals(wDateStr))) {
                        APSMonthShowPo wAPSMonthShowPo =
                                wResult.Result.stream().filter(p -> p.OrderNo.equals(wAPSTaskPart.OrderNo) && p.Date.equals(wDateStr)).findFirst().get();
                        //替换数据
                        if (wRoutePartNameIndexMap.containsKey(wAPSTaskPart.RoutePartName)) {
                            int wIndex = wRoutePartNameIndexMap.get(wAPSTaskPart.RoutePartName);
                            wAPSMonthShowPo.ValueList.set(wIndex, wAPSTaskPart.PlanDayNum.get(wDateStr));
                        }
                    } else {
                        APSMonthShowPo wAPSMonthShowPo = new APSMonthShowPo();
                        wAPSMonthShowPo.Date = wDateStr;
                        wAPSMonthShowPo.OrderNo = wAPSTaskPart.OrderNo;
                        wAPSMonthShowPo.ValueList = new ArrayList<>(Arrays.asList(0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f));
                        //替换数据
                        if (wRoutePartNameIndexMap.containsKey(wAPSTaskPart.RoutePartName)) {
                            int wIndex = wRoutePartNameIndexMap.get(wAPSTaskPart.RoutePartName);
                            wAPSMonthShowPo.ValueList.set(wIndex, wAPSTaskPart.PlanDayNum.get(wDateStr));
                        }
                        wResult.Result.add(wAPSMonthShowPo);
                    }
                }
            }

            //剔除无数据的元素
            wResult.Result.removeIf(p -> p.ValueList.stream().allMatch(q -> q <= 0));

            //按照日期、订单号排序
            wResult.Result.sort(Comparator.comparing(APSMonthShowPo::getDate)
                    .thenComparing(APSMonthShowPo::getOrderNo));

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("APS_QueryMonthDataChangeToShow", e);
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> APS_ResetFirstCheckStatus(BMSEmployee wLoginUser, int wDayTaskID) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            Map<String, Object> wParams = new HashMap<String, Object>();
            wParams.put("ID", wDayTaskID);
            APSTaskPartPointDay apsTaskPartPointDay = mAPSTaskPartPointDayService.SelectPO(wLoginUser, wParams,
                    wErrorCode);
            if (apsTaskPartPointDay != null && apsTaskPartPointDay.ID > 0 && apsTaskPartPointDay.FirstCheckStatus != APSFirstCheckStatus.Default.getValue()) {
                apsTaskPartPointDay.FirstCheckStatus = APSFirstCheckStatus.ToCheck.getValue();
                apsTaskPartPointDay.setUserInfo(wLoginUser);
                mAPSTaskPartPointDayService.UpdatePo(wLoginUser, apsTaskPartPointDay, wErrorCode);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<OMSOrder>> OMS_QueryOrderAll(BMSEmployee wLoginUser, Map<String, Object> wParams,
                                                           Pagination wPagination) {
        ServiceResult<List<OMSOrder>> wResult = new ServiceResult<>();
        wResult.Result = new ArrayList<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            wResult.Result = mOMSOrderService.SelectPOList(wLoginUser, wParams, wPagination, wErrorCode);

            if (wResult.Result != null && wResult.Result.size() > 0) {
                //维护返修数与抽检数
                List<Integer> wOrderIDList = wResult.Result.stream().map(p -> p.ID).collect(Collectors.toList());
                Map<Integer, Integer> wRepairMap = OMSOrderDAO.getInstance().OMS_GetRepairMap(wLoginUser,
                        wOrderIDList, wErrorCode);
                Map<Integer, Integer> wSamplingMap = OMSOrderDAO.getInstance().OMS_GetSamplingMap(wLoginUser,
                        wOrderIDList, wErrorCode);
                for (OMSOrder omsOrder : wResult.Result) {
                    //返修数
                    if (wRepairMap.containsKey(omsOrder.ID)) {
                        omsOrder.ReworkNum = wRepairMap.get(omsOrder.ID);
                    }
                    //抽检数
                    if (wSamplingMap.containsKey(omsOrder.ID)) {
                        omsOrder.SamplingNum = wSamplingMap.get(omsOrder.ID);
                    }
                }
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("OMS_QueryOrderAll", e);
        }
        return wResult;
    }

    //endregion
}
